jQuery live() method
Example
When the button is clicked, hide or show the
element:
$("button").live("click",function(){
$("p").slideToggle();
});
Try it »
Definition and Usage
The live() method wasdeprecatedin jQuery version 1.7, and removed in version 1.9. Please use the on() method instead.
The live() method adds one or more event handlers to the selected elements, and specifies a function to run when these events occur.
Event handlers added through the live() method apply to current and future elements matching the selector (such as new elements created by a script).
**Tip:** To remove event handlers, use the die() method.
Syntax
$(
selector
).live(
event,data,function
)
| Parameters | Description |
|---|---|
| event | Required. Specifies one or more events to add to the element. |
由空格分隔多个事件值。必须是有效的事件。 |
| 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.
jQuery event methods