I’m trying to copy the width and height attributes from one element to another with JavaScript/jQuery but can’t implement it.
I have something like that:
<div id="two">
<img src="picture.jpg" id="one" width="600px" height="300px" />
</div>
and I want to get this:
<div id="two" width="600px" height="300px" >
<img src="picture.jpg" id="one" width="600px" height="300px" />
</div>
You can access the
.widthand.heightproperties of the image element directly.Divs don’t have those properties, so you have to use CSS to set them: