FlipFloop
FlipFloop

Reputation: 1264

jQuery (document).ready() changed in jQuery 3.0?

I saw recently after jQuery 3.0 release, everyone replaced the $ in

$(document).ready(function() {});

to

jQuery(document).ready(function() {});

What is the difference? will the second method work with jQuery 2.1.4?

Upvotes: 2

Views: 8189

Answers (3)

Mushahid Khan
Mushahid Khan

Reputation: 2834

Listed below three function are same JQuery ready()

$(document).ready(function(){

})

and

$(function(){

});

and

jQuery(document).ready(function(){
    // will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.


});

Upvotes: 2

The Process
The Process

Reputation: 5953

It is best practice to avoid conflicts with other libraries using this kind of document.ready(), so $ in here will be an locally-scoped alias to jQuery.

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

Upvotes: 2

unalignedmemoryaccess
unalignedmemoryaccess

Reputation: 7441

Second method works already from version 1.

I use this options always because $ can be used with other libraries as well and you have conflict.

Upvotes: 2

Related Questions