Thursday, September 19, 2013

What do you always use in jQuery Code?


We need to ensure that the page is ready before our JavaScript code is executed. Otherwise,
we may get an error when we try to access an element that is not yet loaded. jQuery
provides us with a way to execute the code after the page is ready. It is the following code:

      jQuery(document).ready(function(){
     // code here.
     });

Actually, what we just used is the following codes:
     $(function(){
     // code here.
     });

The $ sign is a shortcut for jQuery. When we are calling $(something), we are actually
calling jQuery(something).

      $(function_callback) is another shortcut for the ready event.

It is identical to the following:

      $(document).ready(function_callback);

Also, identical to:

      jQuery(document).ready(function_callback);

So, what will you use in your coding jQuery?

No comments:

Post a Comment