I need to change the width and height of the image that will appear as a result of this code, how to get access to its properties?

var div = document.createElement("div"); div.className = 'image'; div.id = 'ImageArea'; div.style.display = 'block'; div.onclick = 'Hide()'; div.innerHTML = '<div class="pic"><img src="images/' + (i+1) + '.jpg"></div>'; document.body.appendChild(div); 
  • Is it too lazy to register for img id?) In general, does the code work? onclick especially. - Sh4dow
  • jQuery: $ ('. pic> img'). width (y) .height (x); updated * - Specter
  • I teach Java the first day, until everything comes quickly ... onclick works, at least in the opera exactly, but not in IE, of course it would be interesting to know how to make a click handler only in js (t. e. without jQuery) - Andrey Talanin

2 answers 2

Register for img unique id="myImg" . But it would be better to add a new img object to the div and access document.getElemetById('myImg').width=xxxx+'px' ;

    It is easier to use Jquery because getting the width values ​​of the image, if they are not specified via CSS and you want them to be specified in the style attribute and not in the external css file, most likely will not succeed ...