开发者

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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜