.live(events, handler) attaches a handler for elements matching the current selector — now and in the future — by binding at document (since 1.3). Removed in 1.9 in favor of .on().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Legacy (jQuery ≤ 1.8)
$("a.offsite").live("click", function () {
alert("Goodbye!");
});
// Same idea with successors
$(document).delegate("a.offsite", "click", fn); // 1.4.3+
$(document).on("click", "a.offsite", fn); // 1.7+ (preferred)
Call
What it does
.live(events, handler)
Bind one or more event types
.live(events, data, handler)
Also pass event.data
.live(eventsMap)
Object of event → handler pairs
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
events
Used in .live(events, handler). Bind one or more event types
handler
Used in .live(events, handler). Bind one or more event types
data
Used in .live(events, data, handler). Also pass event.data
eventsMap
Used in .live(eventsMap). Object of event → handler pairs
Return Value
Return Value
Description
jQuery object
Most 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
$("p").live("click", function () {
$(this).after("
.live(events, handler) attaches a delegated handler for elements matching the selector — now and in the future. jQuery binds at the document, so later-added matches still fire without rebinding.
No. .live() was deprecated in 1.7 and removed in 1.9. Use $(document).on(events, selector, handler) instead. jQuery Migrate 1.x can restore .live()/.die() temporarily while upgrading.
Replace $(selector).live(events, handler) with $(document).on(events, selector, handler). Example: $('a.offsite').live('click', fn) → $(document).on('click', 'a.offsite', fn). Remove with .die() → $(document).off(...).
.live() always attaches at document. .delegate() lets you choose a closer root (often faster). Both are legacy; .on() replaced them in 1.7.
Handlers always travel to document (slow path), chaining like .find().live() fails, iOS click bubbling is awkward, and $(document).off('click') can wipe every .live() click handler. .on() fixes these issues.
Use .die() on the same selector (also removed in 1.9). Modern code uses .off() with the same event and delegation selector.