Get the sum of the outerHeight of all elements of the same class

前端 未结 9 1579
Happy的楠姐
Happy的楠姐 2021-01-03 23:46

I think this is a pretty straightforward problem but...

var outerHeight = $(\'.profile\').outerHeight();
$(\"#total-height\").text(outerHeight + \'px\');
         


        
9条回答
  •  既然无缘
    2021-01-04 00:25

    $("selector") is already a collection. Access directly the .outerHeight() or any other method like .height()

    var total = 0;
    $("div").outerHeight(function(i, v){
       total += v;
    });
    
    alert( total ); // Just to test
    

    var total = 0;
    
    $("div").outerHeight(function(i, v){ total += v; });
    
    alert( total );
    div{background:#eee; margin:3px;}
    
    
    100px
    just lots of breaklines :)



    200px

提交回复
热议问题