How to give height and width to div dynamically?
What is the best possible way using jQuery to give height and width to parent div of an Image.
开发者_运维知识库<div><img src="source.jpg" width="%width" height="%height" /></div>
Please note that , there are more than one tags like this. 3-4 images and DIVS.
thanks in advances.
jQuery solution will be preferred.
Use the jQuery dimensions.
Add a class to each image:
<div><img class='myImage' src="source.jpg" width="%width" height="%height" /></div>
js:
$(".myImage").each(function(){
$(this).parent().css( { width: $(this).width(), height: $(this).height() } );
});
That's it.
Gl
精彩评论