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;});
精彩评论