如何在javascript / jQuery中获取最高子元素的高度? [英] How to get height of the highest children element in javascript/jQuery?

查看:113
本文介绍了如何在javascript / jQuery中获取最高子元素的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个函数来获取div中最高元素的高度。



我有一个包含许多其他内容的元素(动态生成),当我请求使用$(elem).height()的容器元素的高度,我得到比其中的一些内容更小的高度。
里面的一些元素是比这个元素说的大的图像。



我需要知道最高的元素,所以我可以得到它

解决方案

你可以随时做:

  var t = 0; //最高元素的高度(函数运行后)
var t_elem; //最高元素(函数运行后)
$(*,elem).each(function(){
$ this = $(this);
if($ this .outerHeight()> t){
t_elem = this;
t = $ this.outerHeight();
}
});

已编辑,使其重新工作。


I need a function to get the height of the highest element inside a div.

I have an element with many others inside (dynamically generated), and when I ask for the height of the container element using $(elem).height(), I get a smaller height than some of the contents inside it. Some of the elements inside are images that are bigger than the size this element says to have.

I need to know the highest element so I can get it's height.

解决方案

You could always do:

var t=0; // the height of the highest element (after the function runs)
var t_elem;  // the highest element (after the function runs)
$("*",elem).each(function () {
    $this = $(this);
    if ( $this.outerHeight() > t ) {
        t_elem=this;
        t=$this.outerHeight();
    }
});

Edited to make it work again.

这篇关于如何在javascript / jQuery中获取最高子元素的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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