help-Learn how Script Tags and Document Ready Work

The proper format is

<script type="text/javascript">
$(document).ready(function () {
    // some code here
    // more code here

Basically, you’re telling jQuery not do do any work yet (DOM manipulation, i.e. page manipulation) untill the whole html page has loaded completely, finished and ready.

On a small simple page, this may not be a problem. But for a large page that’s pulling content from different places, it may take a few seconds before the page finishes loading. (and if user has a slow browser, internet connection, then it’s even important for you to wait until the page has finished loading.)