Summing outerHeight of multiple divs I am summing the total .outerHeight() of multiple divs like this:

var h = $('#div1').outerHeight() + $('#div2').outerHeight() + $('#div3').outerHeight() + $('#div4').outerHeight();


Is there any way to do this more efficiently?

I was considering something like this (but it doesn't work):

$('#div1, #div2, #div3').outerHeight();
You'll have to add a class to the divs to be able to select them all

&lt;div id="div1" class="sumdiv"&gt;&lt;/div&gt;
&lt;div id="div2" class="sumdiv"&gt;&lt;/div&gt;


Then, use $.each() (http://api.jquery.com/each/)

var sum = 0;
$( ".sumdiv" ).each(function( index ) {
    sum += $(this).outerHeight()
});