I have a small jQuery script for loading the page, a calculation based on the height of a div
is added, and then a margin is added for the result.
The problem is that you are not getting the height value of this div
. In case, there is no CSS pre-determining the height of it, so the height varies according to its content.
jQuery code that I'm using:
$(window).load(function(){
var alturaDivTxt2 = $(".slide-txt").height();
var autoH2 = $(".autoH-banner").css("height");
var alturaDoBanner2 = (autoH2.replace("px","") / 2) + 60;
var alturaTxtFinal2 = alturaDoBanner2 - alturaDivTxt2;
alert('div: '+alturaDivTxt2+' banner: '+alturaDoBanner2+' final: '+alturaTxtFinal2);
$(".slide-txt").css({ "margin-top": +alturaTxtFinal2+"px" });
});
I put that alert
just to see if the data was being processed correctly.
The value of alturaDivTxt2
returns zero .
What could be wrong? I've already tried this function inside $(document).ready()
but it still does not work. I've also tried using .innerHeight()
and other derivatives, without success.