I have some code like this:
var content = document.getElementById('myDivId');
function MyFunction()
{
alert(content.style.height);
}
For some reason, I’m not getting any message box. I have the “body onload” equal to “MyFunction()”.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t have
just free-floating in your script, because then it will run before the
myDivIdelement has actually been created, socontentwon’t end up referring to it. Try putting it inside your onload-handler:instead; or, if you want it to be globally visible, you can at least initialize it inside your onload-handler: