[英]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. 什么是使用jQuery赋予Image的父div高度和宽度的最佳方法。
<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. 3-4张图像和DIVS。
thanks in advances. 在此先感谢。
jQuery solution will be preferred. jQuery解决方案将是首选。
Use the jQuery dimensions. 使用jQuery尺寸。
Add a class to each image: 向每个图像添加一个类:
<div><img class='myImage' src="source.jpg" width="%width" height="%height" /></div>
js: js:
$(".myImage").each(function(){
$(this).parent().css( { width: $(this).width(), height: $(this).height() } );
});
That's it. 而已。
Gl l
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.