Jquery Plugin Structure


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



Copy this code and paste it in your HTML
  1. // $(".someclass").newMethod();
  2.  
  3. (function ($) {
  4. $.fn.newMethod = function () {
  5. return this.each(function () {
  6. alert(this);
  7. });
  8. };
  9. })(jQuery);
  10.  
  11.  
  12.  
  13.  
  14. // usage : $(".someclass").newMethod({ opt1: value1 , opt2 = 'value2' });
  15.  
  16. (function($){
  17. $.fn.methodName = function(options) {
  18.  
  19. var defaults = {
  20. opt1 : value1,
  21. opt2 : "value2"
  22. };
  23. var options = $.extend(defaults, options);
  24.  
  25. return this.each(function() {
  26.  
  27. });
  28. };
  29. })(jQuery);
  30.  
  31.  
  32.  
  33. //usage $.log('message is logged');
  34.  
  35. jQuery.log = function(message) {
  36. alert(message)
  37. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.