jQuery live()Method
Examples
Hide or show a <p> element when clicking a button:
$("button").live("click",function(){
$("p").slideToggle();
});
$("p").slideToggle();
});
Try it Yourself »
Definition and Usage
The live() method in jQuery version 1.7was deprecated, and was removed in version 1.9. Please use theon()method instead.
The live() method attaches one or more event handlers to the selected elements, and specifies a function to run when the events occur.
Event handlers attached with the live() method work for current and future elements matching the selector (such as new elements created by script).
Tip:To remove event handlers, use thedie()method.
Syntax
$(selector).live(event,data,function)
| Parameter | Description |
|---|---|
| event | Required. Specifies one or more events to attach to the elements. Separate multiple event values with spaces. Must be valid events. |
| data | Optional. Specifies additional data passed to the function. |
| function | Required. Specifies the function to run when the event occurs. |
More Examples
Add event handlers to future elements
How to use the live() method to add event handlers to elements that have not yet been created.
Other Extensions
jQuery Event Methods