Skip to content
Related Articles
Open in App
Not now

Related Articles

What is the use of delegate() method in jQuery ?

Improve Article
Save Article
  • Last Updated : 29 Mar, 2022
Improve Article
Save Article

jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. Elaborating the terms, simplifies HTML document traversing and manipulation, browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript development.

The delegate() Method in jQuery is used to add event handlers to the element that are children of selected elements. When the event occurs then the function will be run. This will work for current and future elements (if we want to create some elements later). 


  .delegate(childSelector, event, data, function)

Parameters: This function accepts four parameters.

  • childSelector: This is a required parameter and it is used to specify the children to attach the event handler.
  • event: This is a required parameter and it is used to specify the events to attach to the elements. If there are multiple event values then they will be separated by space.
  • data: This is an optional parameter and it is used to pass the extra data using the function.
  • function: This is a required parameter and it specifies the function to run when the event occurs.

Example: The following code demonstrates the delegate() method in jQuery.


<!DOCTYPE html>
    <title> delegate() Method in jQuery </title>
    <script src=
        <h1 style="color: green;">
        <h2>delegate() Method in jQuery</h2>
                Click the button to change font size, 
                text color and background color of 
            <button> Click me </button>
        $(document).ready(function() {
            $("div").delegate("button", "click", function() {
                $("p").css("background-color", "grey");
                $("p").css("color", "white");
                $("p").css("font-size", "50px");


delegate() method in jQuery


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!