简体   繁体   English

在jQuery中获取div的计算值

[英]To get the computed value of a div in jQuery

I have 3 li under ul . 我有3 liul Now I want to know the height of li . 现在我想知道li的身高。 I do not give height to the li . 我不喜欢li But I want the computed height of li . 但是我想要计算出的li高度。 When I saw the firebug I found the computed height of li is 14px. 当我看到萤火虫时,我发现li的计算高度为14px。 But after use the .height() of jQuery, I got 0px height of that li . 但是在使用jQuery的.height()之后,我得到了li 0px高度。

How can I get the computed value height of li ? 如何获得li的计算值高度?

I tried like the following snippet but I can't get the height: 我尝试了以下代码段,但无法获得高度:

var $ht = jQuery("#access ul ul ul a").height();
console.log($ht);

If your <a> is empty then height() appropriately yields 0. If you would like the height of the <li> then change the code to: 如果您的<a>为空,那么height()适当地产生0。如果您想要<li>的高度,则将代码更改为:

var $ht = jQuery("#access ul li li li").height();
console.log($ht);

If your <li> has margins and paddings you want included in the calculations, then use the following: 如果您的<li>具有要包含在计算中的边距和填充,请使用以下内容:

var $ht = jQuery("#access ul li li li").outerHeight(true);
console.log($ht);

尝试console.log($("#access ul ul ul a").css("height"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM