Latest web development tutorials

jQuery off () method

jQuery Event Methods jQuery Event Methods

Examples

Remove click event all <p> elements on:

$("button").click(function(){
$("p").off("click");
});

try it"

Definition and Usage

off () method is generally used to remove through on () method to add an event handler.

New alternatives jQuery from version 1.7 onwards, off () method is unbind (), die () and undelegate () method. The API method to bring a lot of convenience, we recommend using this method, it simplifies the jQuery code base.

Note: To remove the specified event handler when an event handler is added, the selector string must match on () method parameters passed.

Tip: To add an event run only once and then removed, please use one () method.


grammar

$(selector).off(event,selector,function(eventObj),map)

参数 描述
event 必需。规定要从被选元素移除的一个或多个事件或命名空间。

由空格分隔多个事件值。必须是有效的事件。
selector 可选。规定添加事件处理程序时最初传递给 on() 方法的选择器。
function(eventObj) 可选。规定当事件发生时运行的函数。
map 规定事件映射 ( {event:function, event:function, ...}) ,包含要添加到元素的一个或多个事件,以及当事件发生时运行的函数。


Examples

More examples

From unbind () to off ()
How to use the off () to achieve unbind (the same effect).

From undelegate () to off ()
How to use the off () to achieve undelegate (the same effect).

From the die () to off ()
How to use the off () to achieve die (the same effect).

Remove all added through on () click event handler
How to Remove All through on () method to the click event for all <p> elements on the handler.

Remove one by on () function to add the specified event
How to remove a specified function () method is added through on.

Remove using the event object's event handler
How do I remove an event handler is triggered after a defined number of events.


jQuery Event Methods jQuery Event Methods