Reputation: 5859
Is there a method i can do to determine all child elements width in a single line of code. Adding up all child widths
Upvotes: 6
Views: 6399
Reputation: 322622
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;});
Upvotes: 5
Reputation: 163318
This?
var width = 0;
$('selector > *').each(function() { width += $(this).width(); });
Upvotes: 9