I have to write global function in js file that is loaded initially. I want to write function on it so that it can be accessed from all pages. I am new in jquery. I want to
You can add your own jQuery function by doing the following
$.fn.MyFunction = function()
{
//Code here
}
Then inside of another script or the same script, you can run your function by doing $('#myId').MyFunction();
. This is for running the function on an object. The suggestion below is for just running a function.
Adding it to the jQuery object itself:
$.MyFunction = function()
{
//Code here
}
Then call it as $.MyFunction()