jQuery document ready function

jQuery document ready

Before having jquery,If we want to run code when DOM loading is complete.
We always use windows.load method:

window.load=function(){
     
//Write your code here.
}

Now we use $(document).ready() instead. Because it can greatly improve the response speed of web applications.

But it's different from $(window).load.

$(window).load(function(){
// code 
});
// which instead of 
window.onLoad=function(){
     
//code
}

You can use shortcut of $(function($) { //interal code });while the internal code in the function still uses $as an alias of jquery , no matter what the global $ stand for.

//abbreviation for document ready
$(function($) {
  // code
});

If you want to make sure everything works, it's always safer to write all the code in a document ready function. so you don't have to put your javascript code at the end of the document every time.

date2019-04-02 00:40:56 From:www.jquerypluginhub.com Author:JPH
Related Tags:
Comments

Leave a Reply

Your email address will not be published. Required fields are marked *