Determine the width of all children

Is there a way I can do to determine the entire width of the children in one line of code. Adding all child widths

+6
javascript jquery
source share
2 answers

It?

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

JsFiddle example

+9
source share

If you only need children, do the following:

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

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

Or you can do it with the same result:

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

All Articles