jQuery .on() Event Delegation for Dynamic Elements
Learn how jQuery’s .on() method handles dynamic elements through event delegation, with a table example and browser-based verification.
20 Jan 2026, 15:40 UTC

Problem: events on elements that don't exist yet
You're building a table where rows are added dynamically via AJAX or user input. You need each row to respond to a click, but attaching .click() in a loop fails for new rows, and .live() was deprecated in favor of .on(). You need a solution that works with current jQuery versions and doesn't attach a handler to every now-and-then-created element.
Thesis: one handler on a static parent
The .on() method, introduced in jQuery 1.7, lets you attach a single event listener to a static ancestor. When the event bubbles up from a dynamic descendant that matches the selector, jQuery fires the handler. This is event delegation, and it's the standard pattern for dynamic content.
Concrete example: table-row clicks
// HTML
<table id='task-list'>
<tbody></tbody>
</table>
// JavaScript, after the DOM is ready
$('#task-list').on('click', 'tr', function() {
// this refers to the clicked <tr>
const row = this;
// handle the click, e.g., show details or submit data
});Because the handler lives on #task-list, which exists from the start, clicking any tr—now or later—triggers the function. New rows appended via $('#task-list').append('<tr>…</tr>') inherit the delegation automatically.
Verification in the browser
- Load the page in a browser and open developer tools.
- Append a new row after the handler is bound: $('#task-list').append('<tr><td>new</td></tr>').
- Click the new row. The handler's body executes as if it were bound from the start.
- In the Console, run $._data($('#task-list')[0], 'events'). The output shows a single click handler attached to #task-list, not to individual tr elements.
Limitations and trade-offs
Delegation only works when a stable ancestor exists at the time the handler is attached. If the parent element itself is dynamically created or replaced after the handler binds, the delegation chain breaks. Additionally, if the handler closure captures large objects or references the entire document, memory usage can grow over time—a known consideration in long-lived applications. Another boundary: the selector passed to .on() must be a valid CSS selector that matches the dynamic descendants. Mis-typed selectors silently fail to delegate.
When to reach for an alternative
If you're attaching events to thousands of identical elements and performance is critical, vanilla addEventListener with event delegation at the document level may offer slightly lower overhead. jQuery's .on() adds a thin wrapper, which is negligible for most use cases but worth measuring in high-frequency scenarios.
Closing
Event delegation with .on() is the idiomatic jQuery way to handle events on dynamic elements from version 1.7 onward. Attach the handler to the nearest static parent, use a precise descendant selector, and new elements get the behavior automatically. Verify by adding a node after binding and confirming the event fires. If your parent container is itself dynamic, re-bind after the container stabilizes, or consider moving the handler to a higher, longer-living ancestor.