Posted By

delikassap on 01/31/10


Tagged

plugin jquery structure


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

delikassap


Jquery Plugin Structure


 / Published in: jQuery
 

  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   <

You need to login to post a comment.