Skip to content

Instantly share code, notes, and snippets.

@jgable
Created May 24, 2011 15:46
Show Gist options
  • Save jgable/988954 to your computer and use it in GitHub Desktop.
Save jgable/988954 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
//You need an anonymous function to wrap around your function to avoid conflict
(function($){
//Attach this new method to jQuery
$.fn.extend({
//This is where you write your plugin's name
pluginName: function(options) {
var defaults = {
option1: 'someval'
};
var options = $.extend(defaults, options);
//Iterate over the current set of matched elements
return this.each(function() {
var o = options;
// code to run on each matched element.
});
}
});
//pass jQuery to the function,
//So that we will able to use any valid Javascript variable name
//to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment