How to define jQuery function ? Last Updated : 19 Feb, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Defining the function in jQuery is different from JavaScript, the syntax is totally different. A function is a set of statements that takes input, do some specific computation and produce output. Basically, a function is a set of statements that performs some specific task or does some computation and then return the result to the user. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can call that function. Syntax: $.fn.myFunction = function(){} Below examples illustrate the function definition in jQuery: Example 1: html <!DOCTYPE html> <html> <head> <title> How to Define jQuery function ? </title> <script src= "https://code.jquery.com/jquery-1.12.4.min.js"> </script> <script> $(document).ready(function() { $.fn.myFunction = function() { document.getElementById("geeks").innerHTML = "JQuery function is defined!"; } $(".gfg").click(function(){ $.fn.myFunction(); }); }); </script> </head> <body style="text-align:center"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Defining function in jQuery </h3> <p id="geeks"></p> <button type="button" class="gfg"> Click </button> </body> </html> Output: Example 2: html <!DOCTYPE html> <html> <head> <title> How to Define jQuery function ? </title> <script src= "https://code.jquery.com/jquery-1.12.4.min.js"> </script> <script> $(document).ready(function() { $.fn.myFunction = function() { alert('JQuery function is defined!'); } $(".gfg").click(function(){ $.fn.myFunction(); }); }); </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> Defining function in jQuery </h3> <button type="button" class="gfg"> Click </button> </body> </html> Output: Comment More infoAdvertise with us Next Article jQuery deferred.done() Method S SHUBHAMSINGH10 Follow Improve Article Tags : JQuery jQuery-Misc Similar Reads JQuery | isFunction() method This isFunction() Method in jQuery is used to determines if its argument is callable as a function. Syntax: jQuery.isFunction( value ) Parameters: The isFunction() method accepts only one parameter that is mentioned above and described below: value : This parameter is the value to be tested. Return 2 min read How to execute jQuery Code ? jQuery is an open-source feature-rich Javascript library that is designed for the simplification of HTML DOM Tree traversal & manipulation, event-handling & CSS animation. It is quite popular for its features like light-weight, fast, small, etc, that make it easier to use. The purpose of usi 4 min read jQuery Introduction jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM). jQuery simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser Java 7 min read How to use jQuery library and call functions from it ? In this article, we will see how we can include the jQuery library in the code & use the different call functions. We will be adding some animation effects to see its uses. jQuery is a lightweight JavaScript library that was built to simplify complex JavaScript tasks by generalizing various conc 7 min read jQuery deferred.done() Method This deferred.done() method in jQuery is used to add handlers which are to be called when the deferred object is resolved.Syntax:Â deferred.done(Callbacks [, Callbacks])Parameters:Callbacks: This parameter specifies a function, or array of functions, which are called when the Deferred is resolved.Cal 1 min read How to Use jQuery $(this) in Event ? The scope of this keyword changes according to the scope of the object. The $(this) keyword will refer to the selected element to which the event is attached when used in an event. In this article, we will see the implementation of $(this) with an event in different conditions. Syntax:$('element_sel 2 min read Like