开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜