Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery outer height is zero?

Tags:

jquery

height

Why is the height of my search form 0? It's at least 20px high.

jQuery(function($) { // Document ready
    var s_height = $("#search_form").outerHeight(); // Height of searchform
    alert(s_height) // 0
like image 379
matt Avatar asked Nov 07 '10 18:11

matt


1 Answers

With jQuery you can only get the height of an element if it is visible. So make sure that it is visible at the time that your JS runs, or use one of the several workarounds if you need it to be hidden at the time.

As you mentioned in your comments, the div was hidden and then fading in.

like image 129
Blair McMillan Avatar answered Sep 19 '22 17:09

Blair McMillan