Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make custom function for jQuery selector

How does one go about making a custom function to append to the jQuery selector? Something that would look like:

$('.my_class').my_function();
like image 339
tybro0103 Avatar asked Jul 11 '11 01:07

tybro0103


1 Answers

You want to add the function to jQuery.fn (which is a reference to the jQuery object prototype). For more details check out:

http://docs.jquery.com/Plugins/Authoring

An example\stub:

(function($){
  $.fn.my_function = function(){ ... };

})(jQuery);
like image 67
mikeycgto Avatar answered Oct 22 '22 02:10

mikeycgto