javascript - 选择所有元素中最大的高度

标签 javascript jquery

这是我的代码。

    v=dom.find("ul:first").outerHeight(); // the height of the first li element
            // instead of taking the height of the first li element, it should loop through all
            // li elements and set v to the element with the biggest height

代码中间的注释几乎解释了一切。我需要循环遍历所有 li 元素并取最大的高度,而不是取第一个元素的高度。

最佳答案

var v = 0;
// ...
dom.find('ul:first').children('li').each(function() {
    var height = $(this).outerHeight();
    v = height > v ? height : v;
});

关于javascript - 选择所有元素中最大的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4008851/

相关文章:

javascript - 如何使用jquery最接近应用css

javascript - 固定 float 侧边栏

javascript - $(...).autocomplete 不是函数错误

java - 如何使用 JQuery 和 Bootstrap 布局 json 对象数组

javascript - 使用 jQuery 在屏幕上显示图像时尝试触发事件

javascript - 滚动设定数量的像素后,jQuery 触发一个函数

javascript - 如何让 "onclick"内容显示在动态创建的内容旁边

javascript - 可定制框架和库有什么区别?

javascript - 使用 npm 请求向 SOAP api 发送帖子

javascript - 实现 JQuery 日期选择器