Try moving the script tag and putting it at the very end of the body. They way it is now, the script is trying to run before the elements on the page are loaded. Moving the script tag to the bottom of the body will ensure that all the html elements above it have loaded properly.