开发者

Determine all child elements width

开发者 https://www.devze.com 2023-02-01 20:02 出处:网络
Is 开发者_Python百科there a method i can do to determine all child elements width in a single line of code. Adding up all child widths This?

Is 开发者_Python百科there a method i can do to determine all child elements width in a single line of code. Adding up all child widths


This?

var width = 0;
$('selector > *').each(function() { width += $(this).width(); }); 

jsFiddle example


If you only want children elements, do this:

Example: http://jsfiddle.net/PV2dR/

var t=0;
$('#parent > *').width(function(i,w){t+=w;});

Or you can do this with the same outcome:

var t=0;
$('#parent').children().width(function(i,w){t+=w;});
0

精彩评论

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