I'm using JavaScript to create DOM elements dynamically. In order to animate a slide down effect, I need to retrieve the height of a specific div element. However, both clientHeight and offsetHeight are returning 0. I have confirmed that the div element exists in the DOM by using console.log(). Initially, I have set the style of the div to display:none to hide it. Could this be causing the issue? Any help would be greatly appreciated.
document.getElementsByClassName('myDiv')[0].parentNode.children[1].clientHeight;
To address the problem of display:none, I attempted the following code but the clientHeight still returns 0.
if(obj.style.display == "none"){
obj.style.visibility = "hidden";
obj.style.display = "block";
height = obj.offsetHeight;
obj.style.visibility = "visible";
slideDown(obj,0,height,Math.ceil(height/timeToSlide));
}