Code has been added to clipboard!

Understanding the Now Deprecated jQuery .live() and .die() Functions

Reading time 2 min
Published Jan 8, 2018
Updated Sep 25, 2019

jQuery live and die: Main Tips

  • The jQuery .live() function attached one or more event handlers to selected elements.
  • To remove these handlers, .die() method was used.
  • Both of these methods were removed in 1.9 version of jQuery. Use .on() and .off() instead.

Adding Handlers with .live()

The jQuery .live() method was used to add one or more event handlers to the selected elements.

Example
$("button").live("click", () => {
    $("img").slideToggle();
});

It had the following syntax:

$("selector").live(event, data, function);

jQuery .live() method accepted three arguments:

  • The type of event.
  • Additional data to pass with the function (optional).
  • The function that was executed when the specified event occured.

Note: the jQuery .live() function was deprecated in version 1.7 of jQuery and removed in 1.9. Use .on() instead.

Using .die() to Remove Handlers

The jQuery .die() removed event handlers added with the .live()function.

Example
$("div").die();

We introduce the syntax of .die() function:

$("selector").die(event, function);

It took two parameters:

  • event specified a standard JavaScript event or a custom jQuery.event object.
  • function named a specific handler function to remove (if skipped, all attached handlers were removed).

Note: the jQuery .die() method was deprecated in 1.7 version and removed in 1.9 version. Use .off() instead.

Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX