tag, make sures that most of the elements has been loaded or at least parsed. Or, you just need to wait for document.readyState.
Also, by putting your script below tag is semantically not good. But, you can do it and it won't make a difference for the performance.