How to remove onclick event in jquery

WBOY
Release: 2022-05-18 20:39:15
Original
4288 people have browsed it

Removal method: 1. Use "element object.removeAttr("onclick")" to remove the event defined inside the html tag; 2. Use "element object.unbind("click")" or "Element object.off("click")", removes the event bound by jquery event.

How to remove onclick event in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to remove the onclick event in jquery

1. If the onclick event is defined inside the html tag, you need to use the removeAttr("onlick") method:

removeAttr() method removes one or more attributes from the selected element.

onclick事件
$("#test").removeAttr("onclick");
Copy after login

2. If the current click is an event bound by jquery event, you should use the unbind("click") method:

unbind() method to remove The event handler for 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.

Since jQuery version 1.7, the on() and off() methods are the preferred methods for adding and removing event handlers on elements.

// jquery 绑定事件 $('#test').click(function(){ alert("click"); }) // 使用unbind解除绑定 $("#test").unbind("click");
Copy after login

The example is as follows:

    123   
Copy after login

Click the first button to output the result:

How to remove onclick event in jquery

After clicking the second button, it will move Except for the click event of the first button

Recommended related video tutorials:jQuery video tutorial

The above is the detailed content of How to remove onclick event in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!