javascript - Setting the style.maxWidth from a variable -
my cod this:
<img src="img.png"> <dd id="123">comment</dd> <script> var img = new image(); img.onload = function () { alert(this.width); } img.src = 'img.png'; </script>
this alerts window width of img.png. question is: how set width value element need.
something like:
document.getelementbyid('123').style.maxwidth = this.width;
instead of:
alert(this.width);
the width
dom property of image going number.
the css max-width
property accepts length value.
you need add units number.
= this.width + "px";
Comments
Post a Comment