I have following code
By the time the script is parsed, only the and tags have been loaded. There are several ways you can fix this:
tags at the end of your document, instead of at the beginningwindow.onload = function () { yourCodeHere(); }, which will halt execution of your code until the window has loaded.