jQuery, how to start


/ Published in: jQuery
Save to your folder(s)

IIFE - Immediately Invoked Function Expression.
http://gregfranko.com/jquery-best-practices/#/7
http://gregfranko.com/jquery-best-practices/#/8


Copy this code and paste it in your HTML
  1. // IIFE - Immediately Invoked Function Expression
  2. (function($, window, document) {
  3.  
  4. // The $ is now locally scoped
  5.  
  6. // Listen for the jQuery ready event on the document
  7. $(function() {
  8.  
  9. // The DOM is ready!
  10.  
  11. });
  12.  
  13. // The rest of the code goes here!
  14.  
  15. }(window.jQuery, window, document));
  16. // The global jQuery object is passed as a parameter
  17.  
  18. //--------------------------------------------------
  19.  
  20. // IIFE - Immediately Invoked Function Expression
  21. (function(yourcode) {
  22.  
  23. // The global jQuery object is passed as a parameter
  24. yourcode(window.jQuery, window, document);
  25.  
  26. }(function($, window, document) {
  27.  
  28. // The $ is now locally scoped
  29.  
  30. // Listen for the jQuery ready event on the document
  31. $(function() {
  32.  
  33. // The DOM is ready!
  34.  
  35. });
  36.  
  37. console.log('The DOM may not be ready');
  38.  
  39. // The rest of code goes here!
  40.  
  41. }));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.