Home >Web Front-end >Front-end Q&A >How to use the unbind() method of jquery event
In jquery, the unbind() method is used to remove the event handler of a specified element. The syntax is "element object.unbind(event to be removed, unbind function name, move to be used) event object)"; this method can remove the specified event handler, or terminate the execution of the specified function when the event occurs.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
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.
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).
Note: If no parameters are specified, the unbind() method will remove all event handlers for the specified element.
Note: The unbind() method applies to any event handler added by jQuery.
The syntax is:
$(selector).unbind(event,function,eventObj)
event Optional. 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. The eventObj parameter comes from the event binding function.
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).slideToggle(); }); $("button").click(function(){ $("p").unbind(); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另外一个段落。</p> <p>点击任意段落(p 元素),该段落就会消失。</p> <button>移除所有段落(p 元素)的事件句柄</button> </body> </html>
Output result:
Related video tutorial recommendations:jQuery video tutorial
The above is the detailed content of How to use the unbind() method of jquery event. For more information, please follow other related articles on the PHP Chinese website!