[ACCEPTED]-jQuery height() returns 0 on a visible div - why?-css
Make sure the code is inside the $(window).load 1 [not $(document).ready ]
$(window).load(function () {
newhgt = $('#thetext1').find('div.rhs').css("background", "pink").height();
});
I had the same problem, and I noticed one 4 thing, the div needs to be visible when 3 you call .height();
But, even if the div is visible, the parents of this div needs to be visible. So you must garantee that parents div are visible (display != none)
writing 2 a $('#div').parent().show();
will make a parent visible, you may need 1 anothers parent().show();
You can still use $(document).ready as long 4 as you check to see if the element is loaded 3 first. I chose to go with
$("_element name/id_").load(function() {
$(this).height();
});
I originally found 2 the solution here: http://www.fortwaynewebdevelopment.com/jquery-width-or-height-always-returns-0-fix/
And chose to use the 1 answer in the first response.
I solved my problem like this:
setInterval(function(){
alert($("#element").height());
}, 1000);
It works for 1 me.
newhgt = $('#thetext1').find('div.rhs').css("background", "pink")[0].getBoundingClientRect().height;
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.