Script does not work when on

In some cases, if you are trying to operate on items that are on the page, if you javascript loads and executes before the rest of the page has finished loading, you will get errors and/or your code will not appear to work.

This is one reason it is recommended to put links to javascript files at the bottom of the page.

Another good practice is to only run your when the document has finished loading, in jQuery is is normally done using the following syntax:

$(document).ready(function(){
   // Your javascript
}

Leave a Comment