Jquery More divs width!
I have an div wrapper and some div-s inside of it. Can I calculate all div-s width inside the wrapper and give the total width to the wrapper? Thank you!
<div id="wrapper">
<div class="image"><img src="images/1.jpg">开发者_StackOverflow中文版</div>
<div class="image"><img src="images/2.jpg"></div>
<div class="image"><img src="images/3.jpg"></div>
<div class="image"><img src="images/4.jpg"></div>
<div class="image"><img src="images/5.jpg"></div>
<div class="image"><img src="images/6.jpg"></div>
</div>
function calcWidth() {
var width = 0;
$("#wrapper").find("div").each(function(){
width += $(this).width();
});
return width;
}
$("#wrapper").width(calcWidth());
Like this?
精彩评论