Can someone please explain to me the difference between
$(document).ready(function(){…});
and
$(‘document’).ready(function(){…});
Notice that there are no quotes within the first document block.
Thanks
Can someone please explain to me the difference between
$(document).ready(function(){…});
and
$(‘document’).ready(function(){…});
Notice that there are no quotes within the first document block.
Thanks
$(document) passes the document element to JQuery.
$(‘document’) passes the CSS selector ‘document’ to JQuery.
Neither is necessary as the ready method in jQuery should no longer be called directly.
You should either use:
$(function(){…});
which implicitly runs the ready method or if the JavaScript is at the bottom of the page you can use:
(function($){…})(jQuery);
and so run the code straight away without needing to test ready.
thank you for the detailed explanation