Home  >  Article  >  Web Front-end  >  How to remove click event in jquery

How to remove click event in jquery

WBOY
WBOYOriginal
2021-12-13 17:58:086700browse

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();".

How to remove click event in jquery

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:

How to remove click event in jquery

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn