How to define a function in jQuery

  2344 views   2 years ago Javascript jQuery

Use the syntax $.fn.myFunction=function(){}

The syntax for defining a function in jQuery is little bit different from the JavaScript. Let's take a look at the following example to understand how to define a function in jQuery.

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Define a Function in jQuery</title>
<script src=""></script>
    $.fn.myFunction = function(){ 
        alert('You have successfully defined the function!'); 
    <button type="button" class="call-btn">Click Me</button>


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]