jQuery Event - live() Method
Example
Hide or show the p element when the button is clicked:
$("button").live("click",function(){ $("p").slideToggle(); });
Definition and Usage
The live() method attaches one or more event handlers to the selected elements and specifies the function to be executed when these events occur.
Event handlers attached by the live() method apply to both current and future elements that match the selector (such as new elements created by the script).
Syntax
$().live(event,data,function)
Parameters | Description |
---|---|
event |
Required. Specifies one or more events to be attached to the element. Multiple events separated by spaces. Must be valid events. |
data | Optional. Specifies additional data to be passed to the function. |
function | Required. Specifies the function to be executed when the event occurs. |
More examples
- Adding event handlers to future elements
- How to use the live() method to add event handlers to elements that have not yet been created.