Friday, December 17, 2010

JQUERY --> The Document Ready Function

You might have noticed that all jQuery functions are inside a document.ready() function:


$(document).ready(function(){

   // jQuery functions go here...

});



This is to prevent any jQuery code from running before the document is finished loading (is ready).



Here are some examples of actions that can fail if functions are run before the document is fully loaded:
  • Trying to hide an element that doesn't exist
  • Trying to get the size of an image that is not loaded

No comments:

Post a Comment