jQuery .delegate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Event Handler

Definition

.delegate(selector, eventType, handler) attaches a handler on a root element for events from matching descendants — including elements added later (since 1.4.2). Argument order differs from .on().

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// Deprecated (3.0+) — selector first
$("table").delegate("td", "click", function () {
  $(this).toggleClass("chosen");
});

// Modern equivalent — events first (1.7+)
$("table").on("click", "td", function () {
  $(this).toggleClass("chosen");
});
CallWhat it does
selectorFilter which descendants may trigger the handler
eventType / eventsEvent name(s), or a map of events → handlers (1.4.3+)
eventDataData passed to the handler via event.data
handlerFunction to run (*not needed when using an events map)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Pick a root that will stay in the DOM (list, table, form, or body).
Step 2Call .delegate(selector, eventType, handler) on that root.
Step 3Inside the handler, this is the matched descendant that triggered the event.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Dynamic Children

Click a paragraph to append another — new ones stay clickable.

jQuery
$("body").delegate("p", "click", function () {
  $(this).after("

Another paragraph!

"); });
Try It Yourself

How It Works

  1. Bind. One handler on body for clicks from p.
  2. Match. jQuery checks the bubbled target against "p".
  3. Act. this is the clicked paragraph; append a sibling.

Example 2 — Migrate to .on()

Same behavior — modern parameter order.

jQuery
// Legacy
$("table").delegate("td", "click", function () {
  $(this).text("clicked");
});

// Preferred (1.7+)
$("table").on("click", "td", function () {
  $(this).text("clicked");
});
Try It Yourself

How It Works

  1. Legacy. Selector comes before the event name.
  2. Modern. Event name comes first; selector is second.
  3. Same root. Still bind on table, not each td.

Example 3 — Event Data

Pass extra data into the handler the same way as .on().

jQuery
$("#list").delegate("button", "click", { source: "toolbar" }, function (event) {
  $("#out").text(
    $(this).text() + " · " + event.data.source
  );
});
Try It Yourself

How It Works

  1. Pass. The third argument is plain data for the handler.
  2. Read. Access it as event.data.
  3. Scope. Useful when one handler serves several roles.

Frequently Asked Questions

.delegate(selector, eventType, handler) attaches a handler on a root element for events from matching descendants — now or added later. One parent listener covers many children.
Yes. As of jQuery 3.0, .delegate() is deprecated. Prefer .on(events, selector, handler) since jQuery 1.7. The method still works for legacy code, but new projects should not use it.
Swap argument order: $(root).delegate(selector, events, data, handler) becomes $(root).on(events, selector, data, handler). Example: $('table').delegate('td', 'click', fn) → $('table').on('click', 'td', fn).
.live() always delegated from the document and could not choose a closer root. .delegate() lets you pick the parent (table, list, form). .live() was removed in 1.9; .delegate() was superseded by .on() and deprecated in 3.0.
You bind once on a stable parent instead of many handlers on each child. New elements added later still work without rebinding, and memory use stays lower on long lists.
Use .undelegate() for handlers attached with .delegate(), or migrate to .on() / .off(). Prefer .off(events, selector, handler) in modern code.

Next: .undelegate() Method

See how to remove handlers attached with .delegate().

.undelegate() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful