简体   繁体   中英

To get the computed value of a div in jQuery

I have 3 li under ul . Now I want to know the height of li . I do not give height to the li . But I want the computed height of li . When I saw the firebug I found the computed height of li is 14px. But after use the .height() of jQuery, I got 0px height of that li .

How can I get the computed value height of 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:

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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