-1

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() { 
                alert('test'); 
             }

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

1 Answers1

1

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() {
  alert("test");
}

jQuery.myFunction = myFunction;

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

jQuery.fn.myFunction = myFunction;

jQuery({}).myFunction(); // `$.fn` chained to `jQuery()` call
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
guest271314
  • 1
  • 15
  • 104
  • 177