Why am I getting a document.getElementById("…") is null error?

Hello there,
So as to save myself the time and effort of getting it all on to here, while that all picture data files are integrated, and to help you view it from the HTML editor within your choice, (I propose Notepad++ for that awesome color coding) Relating to placed this file and also all required components from a.zip file for you personally here.

http://cid-7cc3864d98261b77.business.live.com/browse.aspx/Shared%20Files

I am just new for you to JavaScript, thus I’m most likely just lacking something, but I’m unsure what its.I ‘m getting one that states that “document.getElementById(“hour1″) is usually null”

I carry out have every one of the required IDs and everything.

This is what the particular code can ultimately complete.(Not the whole thing is below, I appeared to be just testing some of it out and about.)
This is the clock that will display pictures representing this numbers as opposed to text amounts.
The portion that’s present within the.zip file is just for the best hour digit.(I do possess a miscellaneous “1” from the table around there.It serves no functional purpose besides to have got something else within the table for the moment.)

The signal looks on the hour.In the event the hour is definitely between JUST ONE and ON THE LOOKOUT FOR or TOUGH LUCK and 21 YEARS OLD, it shows a ignore image.Else, it displays an image representing the number 1.

An individual can decide on three diverse colors for your clock.The preferred color is going to be converted for you to represent many.That number is then found in the insurance coverage.getElementById number reference to select the correct colored range image.

I carry out have a quality comments within the code, so that may help you too.

The images is going to be inserted suitable table.

In order that is how it works.Or should work anyway.So if you can help my family out, that will be fantastic!

Thanks ahead of time!
-JDDellGuy

The JavaScript from the head component starts to operate immediately.This freezes the actual loading of the remaining page as you move the JavaScript executes.The element while using id attribute of hour1 hasn’t entered the particular DOM still so if your script grows to that stage it looks into the DOM for your element nonetheless can’t find it because page has not fully filled yet plus returns null.

One solution would be to put your current script tag prior to the closing body tag to ensure the web page has loaded ahead of the script starts to undertake its idea.

Leave a Reply