2

I am having a problem with getting the outer height of a list item - similar to the below post: jQuery: Get height of hidden element in jQuery

Here is my code:

function tabload() {
    $('.tab li:first-child').addClass('selected');

    $(".tab ul").css({ 'position': 'absolute', 'visibility': 'hidden', 'display': 'block'});

    var h = $(".tab ul").outerHeight(true);

    $(".tab ul").css("height", h);

    $(".tab ul").css({'position': 'relative', 'visibility': 'visible', 'display': 'none' });
};

Am i doing something wrong?

Community
  • 1
  • 1

4 Answers4

1

I have blogged about this issue before since there are a few other similar questions here on stackoverflow. Take a look at the code in this blog post

I initially developed it just for the width method, but based on comments the code has evolved to include inner/outer dimensions.

Tim Banks
  • 7,099
  • 5
  • 31
  • 28
  • I did see this post actually but wasn't able to solve it myself. Not sure if it matters but i am using asp.net with razor mvc. would it help if i added my css and html? Ive already started to recode this, but surely there is a solution! –  Aug 10 '11 at 13:56
  • Being able to see your HTML and CSS would help recreating the issue. I could then play around with and see what I can find. – Tim Banks Aug 10 '11 at 14:06
  • Here is the HTML/CSS - Ive removed some code as its in asp.net mvc razor. CSS ul.tab {margin-top:10px; clear:both; position:relative;} ul.tab li {float:left; background:none;} ul.tab ul {display:none; position:absolute} ul.tab li.selected ul {display:block; left:0;} ul.tab li a {display:block;} ul.lineup li {float:left; height:auto !important;} HTML
      • Name
    –  Aug 10 '11 at 14:14
  • What value are you getting for the height and what value are you expecting? – Tim Banks Aug 10 '11 at 14:33
  • I am getting 0 but expecting the height to be whatever is loaded in the
  • - this depends on what comes back from the server for that particular
  • –  Aug 10 '11 at 14:39
  • There must be something else affecting it that I don't have. I set up an example here: http://jsfiddle.net/YReWs/ and I am getting a non-zero value for h inside of tabload. – Tim Banks Aug 10 '11 at 14:48