Chaudhary Asghar Ali Chaudhary Asghar Ali - 5 months ago 33
jQuery Question

How can we add our custom function in jquery?

I want to add my custom function in jquery library so that i can access them using $ sign.

I am trying using this way but its not working

$.fn.myFunction = function() {

and i also want to know that can we rename any function which already available in jquery?

Answer Source

If you are attempting to define a function at jQuery, or jQuery alias $ use $ without .fn, which attaches function to an object or selector chained to jQuery() call.

function myFunction() {

jQuery.myFunction = myFunction;

jQuery.myFunction(); // called on `jQuery` object

jQuery.fn.myFunction = myFunction;

jQuery({}).myFunction(); // `$.fn` chained to `jQuery()` call
<script src="">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download