开发者

Jquery More divs width!

开发者 https://www.devze.com 2023-01-31 21:54 出处:网络
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?

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

精彩评论

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