So I'm trying to access the .css('height') of an element and it keeps returning 0px regardless of what it's height is. I've put a couple alerts to see what it gets in the $(document).ready() function so it should be accessible by then. The height property is being set in the actual css file, not dynamically so I don't know why it's giving the wrong thing back.

Here is the location:
(the 2 alerts are heights for the elements #taskbar and #taskbar_holder. I'm running those from line 11 and 12)

Thanks in advance for any help!

Dani AI

Generated

Nice that fixed it. When jQuery returns a zero height for an element that should have size, the cause is almost always about timing or the element being effectively collapsed or hidden. Common, practical checks that resolve this quickly:

  • Make sure the element is visible and actually in the DOM (elements with display:none or detached nodes report zero).
  • Verify the CSS that defines the height was loaded and applied; inspect the element's computed style in DevTools.
  • If the element’s height depends on images, fonts, or other resources, measuring too early will give zero — wait for the full load.
  • Percentage heights need explicit heights on ancestor elements; otherwise the computed height can be zero.
  • Floated children can collapse a parent; confirm the containing block actually expands (clearfix or check children sizes).
  • Try different measurement methods: jQuery’s .height()/.outerHeight() or native offsetHeight / getBoundingClientRect().

Quick examples to try:

$(window).on('load', function(){
  var h = $('#yourElement').outerHeight();
  console.log(h);
});

var h = document.getElementById('yourElement').getBoundingClientRect().height;

For details on how .css() differs from methods that return numeric heights, see the jQuery docs for .css() and .height(). For low-level layout measurements and timing, see the browser API docs for getBoundingClientRect().

Nevermind, figured out a fix :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.