what this mean
Note that the call must be made inside of a $(document).ready() call, or the plugin will not work!
any1?
what this mean
Note that the call must be made inside of a $(document).ready() call, or the plugin will not work!
any1?
— short answer: the phrase means "start the plugin only after the page's DOM is ready." If your init code runs before the elements it needs exist, the plugin cannot attach itself and will appear to do nothing. 's links about the dollar sign are useful background; below focuses on the "ready" part and practical checks.
Here are common ways to ensure code runs after the DOM is built:
$(document).ready(function() {
$('#yourElement').yourPlugin();
}); $(function() {
$('#yourElement').yourPlugin();
}); If another library has taken over $, call jQuery explicitly or wrap in an IIFE:
jQuery(document).ready(function() {
jQuery('#yourElement').yourPlugin();
});
(function($){
$(function(){
$('#yourElement').yourPlugin();
});
})(jQuery); Quick troubleshooting checklist when a plugin "will not work":
$('#selector').length in console.window.onload instead of DOM ready.async, avoid it for dependent scripts; defer keeps order and runs after parsing.jQuery(...) or an IIFE that passes jQuery as $.For official details see the jQuery ready docs and MDN on DOMContentLoaded:
jQuery ready documentation
MDN on DOMContentLoaded
Here are a couple points of information about the use of $ in JavaScript and jQuery more specifically.
http://www.smashingmagazine.com/2014/05/29/mystery-jquery-object-syntax-basic-introduction/
http://www.authenticsociety.com/blog/JavaScript_DollarSign
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.