jQuery live()Method

jQuery 事件方法jQuery Event Methods

Examples

Hide or show a <p> element when clicking a button:

$("button").live("click",function(){
$("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.


jQuery 事件方法jQuery Event Methods

Other Extensions