SyntaxFix
Write A Post
Hire A Developer
Questions
You probably included your JavaScript before the HTML: example.
You should either execute your JavaScript when the window loads (or better, when the DOM is fully loaded), or you should include your JavaScript after your HTML: example.