I have a javascript code that points to an image using getElementById. But when I debug it in firebug, it says that my variable has a value of “null”. Here is my code:
var image = document.getElementById('myImage');
image.src = "imageone.png";
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.
That’s because there is no element with that id.
If the element actually have that id, then the reason is that the element hasn’t been parsed yet when the code runs. Put it in the
loadevent to run it after the entire page has been parsed:Alternatively, you can put the script block in the
bodyelement, below the image tag.