jQuery Ready() Initialization

Using jQuery initialization

jQuery logojQuery offers a very convenient method to do JavaScript initialization. Many JavaScript and jQuery statements require existence of site elements and tags, and can not be run until after the elements and tags exist. Some use the onload attribute of the tag. To some, this implies moving the running of the JavaScript or jQuery initialization to the end of the page. However. JavaScript and jQuery offer other methods that solve this problem. They provide methods to run initialization after the DOM hierarchy has been initialized.

jQuery’s ready() works great to permit the defining of initialization functions and then executing these functions when the DOM is ready.

A reason to use the jQuery ready() initialization rather than javascript.onload() or placing the onload in the body tag … jQuery allows you to create initialization tasks wherever it is best encapsulated with the code it supports, yet it is gathered together with all other identified initialization activities and executed as a group when the DOM is ready.

To use jQuery ready(), wrap your initialization activities in the ready wrapper as follows:

 

Shortcut for jQuery Ready() Notation

Alternately, you may use a shorthand notation to run an initialization by invoking initialization handling as follows:

Leave a Reply