Exploring jQuery .live() and .die()
Tuesday, October 5th, 2010
Most developers I talk to have limited knowledge of jQuery’s .live() function. Typically they know what it does, but not how it works, and thus are not entirely comfortable using it. And usually they’ve never heard of .die(), which unbinds .live() events.
Even if you are familiar with these, are you aware of the problem with .die()?
What is .live()
The .live() function is similar to .bind(), except that it allows you to bind events to DOM elements now and in the future; you can bind events to elements that don’t exist yet in the DOM. Consider the following example.
Let’s say you want to warn the user that they’re about to leave your site when they click on any link:
$('a').click( function() {
alert("You are now leaving this site");
return true;
});
});
Note that the .click() method is merely a convenience method for the more general .bind() method, so the following is equivalent to above:
$('a').bind( 'click', function() {
alert("You are now leaving this site");
return true;
});
});
But now, let’s say you add another link to the page via javascript.

