Put the javascript declaration at the bottom of the body tag where I thought it was but turned out it was just outside the body.