获取同一类所有元素的outerHeight之和 [英] Get the sum of the outerHeight of all elements of the same class

查看:65
本文介绍了获取同一类所有元素的outerHeight之和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个非常简单的问题,但是...

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

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

现在var outerHeight给了我只有类.profile的第一个元素的externalHeight.

Right now the var outerHeight gives me the outerHeight of only the first element with the class .profile.

如何获取类为.profile all 个元素的externalHeight的总和?

How can I get the sum of the outerHeights of all elements with the class .profile?

推荐答案

遍历每个匹配的元素并累加外部高度:

Loop through each matching element and add up the outerheights:

var outerHeight = 0;
$('.profile').each(function() {
  outerHeight += $(this).outerHeight();
});
$("#total-height").text(outerHeight + 'px');

这篇关于获取同一类所有元素的outerHeight之和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆