开发者

How to give height and width to div dynamically?

开发者 https://www.devze.com 2022-12-08 15:26 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消