Home >Web Front-end >Front-end Q&A >How to cancel all events of an element in jquery
In jquery, you can use the unbind() method to unbind all events of an element, the syntax is "$(selector).unbind();". The unbind() method can remove all event handlers bound to the element, or specify an event handler; when the method does not specify parameters, all events can be removed.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the unbind() method to unbind all events of an element.
The unbind() method removes the event handler of the selected element.
This method can remove all or selected event handlers, or terminate the execution of the specified function when an event occurs.
$(selector).unbind(event,function,eventObj)
Parameter | Description |
---|---|
event | Yes select. Specifies one or more events to be removed from the element. Multiple event values separated by spaces. If only this parameter is specified, all functions bound to the specified event are removed. |
function | Optional. Specifies the name of the function to unbind the specified event from the element. |
eventObj | Optional. Specifies the removed event object to use. this
eventObj parameters come from the event binding function. |
#This method can also unbind the event handler through the event object. This method is also used to unbind events within itself (such as deleting the event handler after the event has been triggered a certain number of times).
When the unbind() method does not specify parameters, all event handlers of the specified element will be deleted.
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("p").click(function() { $(this).slideToggle(); }); $("p").hover(function() { $(this).css("color","red"); }); $("button").click(function() { $("p").unbind(); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>鼠标移入任意段落(p 元素),该段落字体颜色会变红。</p> <p>点击任意段落(p 元素),该段落就会消失。</p> <button>移除所有段落(p 元素)的事件句柄</button> </body> </html>
As you can see, in the above example, both the mouse click event and the move-in event were canceled
[Recommended learning :jQuery video tutorial、web front-end video】
The above is the detailed content of How to cancel all events of an element in jquery. For more information, please follow other related articles on the PHP Chinese website!