Making functions in JQuery
I feel like using too much classic javascript, and really like to encapsulate my functionality in JQuery.
For example I have the following JS function:
function DoStuff(param) {
// Do stuff with param
return foo;
}
from a JQuery button click I do like this.
$("#btnMyButton").click(function () {
//Do stuff
DoStuff(myParam);
// Do some other stuff
});
What is the best way to define a JQuery function and call it?
I found this notation:
(function( $ ){ $.fn.
myfunction
= function() { alert('hello world'); }; })( jQuery );
and then the example says to call it like:
$('#my_div').myfunction();
But how can I call my DoStuff function without having a div or anything else.
I just want to call it like this:
$.DoStuff