Well, look at the file. Does p1 exist when the script is encountered?
Some people will put the script at the end of the file, after the DOM has been constructed, and there are claims that this is more performant than other locations. (I have yet to see much of any difference.)
But most people will put initialization code in one of a load event handler, or a ready handler (if using jQuery).