Reputation: 1264
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
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
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
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