jQuery .live() Method

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

Definition

.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)
CallWhat 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

ParameterDescription
eventsUsed in .live(events, handler). Bind one or more event types
handlerUsed in .live(events, handler). Bind one or more event types
dataUsed in .live(events, data, handler). Also pass event.data
eventsMapUsed in .live(eventsMap). Object of event → handler pairs

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
$("p").live("click", function () {
  $(this).after("

Another paragraph!

"); });
Try It Yourself

How It Works

  1. Bind. One document-level handler for clicks matching "p".
  2. Match. Bubbled targets are tested against that selector.
  3. Act. this is the clicked paragraph; append a sibling.

Example 2 — return false

Cancel default action and stop bubbling from a live link handler.

jQuery
$("a").live("click", function () {
  $("#out").text("Blocked navigation");
  return false; // preventDefault + stopPropagation
});

// Or cancel default only:
// event.preventDefault();
Try It Yourself

How It Works

  1. Live. Clicks on any a (including future ones) reach document.
  2. Return false. Blocks navigation and further bubbling.
  3. Note. Before 1.7, stopPropagation() alone often failed to stop other live handlers — return false was safer.

Example 3 — Migrate to .on()

Official rewrite templates — same behavior, modern API.

jQuery
// Legacy
$("a.offsite").live("click", fn);

// Intermediate
$(document).delegate("a.offsite", "click", fn);

// Preferred (1.7+)
$(document).on("click", "a.offsite", fn);
Try It Yourself

How It Works

  1. Live. Selector is on the jQuery collection; root is fixed to document.
  2. Delegate / on. Root is explicit; selector moves into the call.
  3. Order. .on(events, selector, handler) — events first.

Frequently Asked Questions

.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.

Next: .die() Method

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

.die() 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