If you want to make a functionality that can be used anywhere in the code. For example, you want some method that can be called on the jquery selection and it can perform number of operations on the selection. For this, you can write a plugin.
For example if we want to create a plugin that makes color of the text red within set of elements(p, span, a). Then we have to add a function named method1 to $.fn and it will work as other jquery object methods.
$.fn.method1 = function() {
this.css( "color", "red" );
};
$( "p" ).method1();
$("span").method1();
$("a").method1();
0 Comment(s)