Home > Article > Web Front-end > How to remove click event in jquery
Jquery method to remove click events: 1. Use the "$(specified element)" statement to obtain the specified element object that has been bound to the click event; 2. Use the unbind() method to delete the click of the specified element object. Event, the syntax is "element object.unbind();".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How to remove the click event in jquery
In jquery, you can use the unbind() method to remove the click event.
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 the event occurs. ubind() works with any event handler attached via jQuery.
Let’s take an example to see how to remove the click event of an element. The example is as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").click(function(){ $(this).slideToggle(); }); $("button").click(function(){ $("p").unbind(); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另一个段落。</p> <p>点击任何段落可以令其消失。包括本段落。</p> <button>删除 p 元素的click事件</button> </body> </html>
Output result:
Related video tutorial recommendations: jQuery video tutorial
The above is the detailed content of How to remove click event in jquery. For more information, please follow other related articles on the PHP Chinese website!