开发者

Determine all child elements width

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜