Posted By

ira on 01/08/10


Tagged

javascript jquery plugins


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

davidsi
dancrew32
jaypplr
zreedeecom
bennettstone


jQuery plugin starter code


 / Published in: jQuery
 

Basic skeleton for a plugin. Contains an example to show where code needs to go.

  1. (function($){
  2.  
  3. $.fn.pluginName = function(params){
  4.  
  5. // give the options their default value
  6. options = $.extend({
  7.  
  8. option1: 'default text' // example option (delete)
  9.  
  10. }, params);
  11.  
  12. // plugin actions. Most code should go here.
  13. this.each(function(){
  14.  
  15. $(this).fadeOut('slow', function(){ $(this).html(options.option1).fadeIn() }); //example action (delete and replace with your code)
  16.  
  17. });
  18.  
  19. return this; // keeps jquery chaining going
  20.  
  21. }
  22.  
  23. })(jQuery);
  24.  
  25. $('p').pluginName({option1:'new text'}); // call the plugin, pass it the options

Report this snippet  

You need to login to post a comment.