/ Published in: jQuery
JQUERY READY EVENT BEST PRACTICE
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script> // IIFE - Immediately Invoked Function Expression (function(yourcode) { // The global jQuery object is passed as a parameter yourcode(window.jQuery, window, document); }(function($, window, document) { // The $ is now locally scoped // Listen for the jQuery ready event on the document $(function() { console.log('The DOM is ready'); // The DOM is ready! }); console.log('The DOM may not be ready'); // The rest of code goes here! })); </script>
URL: http://gregfranko.com/jquery-best-practices/#/8