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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -