Latest web development tutorials

jQuery live () method

jQuery Event Methods jQuery Event Methods

Examples

When the button is clicked, hide or show the <p> element:

$("button").live("click",function(){
$("p").slideToggle();
});

try it"

Definition and Usage

live () method in jQuery version 1.7 is obsolete and is removed in version 1.9. Please use the on () instead of the method.

live () method is to add one or more elements selected from the event handler, and a predetermined function to run when these events occur.

By live () method to add an event handler applicable current and future elements matching the selector (such as a new element created by the script) in.

Tip: To remove an event handler, use die () method.


grammar

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

参数 描述
event 必需。规定添加到元素的一个或多个事件。

由空格分隔多个事件值。必须是有效的事件。
data 可选。规定传递到该函数的额外数据。
function 必需。规定当事件发生时运行的函数。


Examples

More examples

Add an event handler to the next element
How to use the live () method to add an event handler to the element has not been created.


jQuery Event Methods jQuery Event Methods