用类找到最高的元素:jQuery [英] Find the tallest element with a class: jQuery

查看:62
本文介绍了用类找到最高的元素:jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个jQuery函数,该函数搜索具有相同类的元素列表,并返回最高元素的高度.

I need a jQuery function that searches a list of elements, with the same class, and returns the height of the tallest element.

任何帮助都会很棒.

推荐答案

var maxHeight = 0;
$('.myclass').each(function(){
   maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
});
alert(maxHeight);

或者:

var maxHeight = Math.max.apply(null, $('.myclass').map(function () {
    return this.clientHeight; // or $(this).height()
}));

这篇关于用类找到最高的元素:jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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