Back to Top

Event Delegation in jQuery

Event Delegation in jQuery

In the learning process of jQuery, I found the bind event of jQuery which you can use with bind() method or can use on() method, someone use delegate() or live(). But all do the same process that is Event Delegation.I have used all but do not fully understand the difference between all.

So, The Simple reason of so many types of binding method is the updated version of jQuery added on () method for version 1.7 and later.

If you are using jQuery constantly for your web application, You may have heard about the event delegation concept of jQuery. Event Delegation concept is very convoluted design pattern which is useful when you want to add the event to an element which are the child element of any element.

What is Event Delegation?

DOM Structure of scripting language is complex to understand.Event Delegation is an optimization technique for event binding of DOM element by using the principle of event bubbling through binding events to the parent element.


jQueryObject . delegate (selector, types, data, fn );

New Delegate Function Syntax:



$ ( "ancestor" .) on ( "Click" , "Selector" [, Data ], handler );


Events: You can enter one or more space-separated event types such as “click”.
Selector: A selector string for the descendant selector filter element triggering event.
Data: is optional.When an event is triggered, data will be passed to the event handler.
Fn: Function called when the event is triggered.

.on() event delegation method to bind the currently selected elements with the jQuery object. Before jQuery 1.7, .bind(),.delegate() and .live() three different methods were used for the event delegation in jQuery. Now, only .on() method is used and provides all the functionality required to bind event handlers.To attach an event that runs only once, you can use the .one () method.

Official documentation suggests:

As of jQuery 1.7, the .on () method is the preferred method for attaching event handlers to a document.

.bind() method is directly bind the element whereas .live() method is a way to bind by bubbling elements. But .delegate () is a more accurate than the .live () method and .on() method is a new binding mechanism.

$ ("#id"). on('click', function () { 
// do something 

As above code, the click event bind to the document object and when the click event occurs on any element of the page to be processed, propagate the document object.

Let’s check below HTML Code:

Here in the html, placed a div and several p tags inside the div element.When to click the p elements. P elements on the page we will bind click event.





Now following jQuery code will perform Event Delegation on the div with parent element id. Here I am going to bind the event to all elements which are the child of div.

Now lets see the actual code:

// To Get the object of parent Element
$( "div" ).delegate( "p" , "click" , function () {
    // Here this points to trigger a click event of p elements

Using delegate method, you can accurately locate the event and event bubbling overhead can be reduced.If this article helped you, then don’t forget to share it on Facebook and join thecreativedev on Facebook.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts


Posted on 2 years ago


Hello world

Posted on 1 week ago

Nick Carter

WordPress Template Hierarchy Tutorial

Posted on 3 years ago


Hello world

Updated 1 week ago

Nick Carter

In depth Understanding of Laravel Core

Updated 2 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 4 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 5 years ago