Marty.H Marty.H - 2 months ago 24
jQuery Question

What can cause height() to return as a negative value?

This is my code to see the height of an element:

console.log($(".divText").height()); // Returns negative value
console.log($(".divText").outerHeight()); // returns zero


I have the code execute on a click event, the page displays the element, I am selecting the correct element and there are no floats involved. What else can cause this to happen?

Answer

Put that code inside

$(document).ready(function(){
    //your code
});