Recently I wrote a template on how to extend jQuery and how to create your own functions. Since then I came across even smaller code snippet on how to add your own custom functions, in other words how to create plugins for jQuery. So without further ado:
$.fn.myFunction = function() {
return $(this).addClass('changed');
} And now, use it like this:
$('.changePlease').myFunction(); And that is all there is :)



7 comments:
Thanks a lot!!
:)
What if I need a parametrized function?
Thanks!
Nice
@Gabriel Porras, you can simply do this:
$.fn.myFunction = function(MYVAR) {
var args = MYVAR;
...
}
@ABitSmart, no probs. @Antoine thanks.
good article thanks
very helpful :)
So simple, yet so powerful!!!
Post a Comment