- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove event handlers using jQuery?
Once an event handler is established, it remains in effect for the remainder of the life of the page. There may be a need when you would like to remove event handler.
jQuery provides the unbind() command to remove an exiting event handler. The syntax of unbind() is as follows.
The following is the description of the parameters −
- eventType − A string containing a JavaScript event type, such as click or submit. Refer to the next section for a complete list of event types.
- handler − If provided, identifies the specific listener that's to be removed.
Example
You can try to run the following code to learn how to remove event handlers using jQuery −
<html> <head> <title>jQuery Unbind</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { function aClick() { $("div").show().fadeOut("slow"); } $("#bind").click(function () { $("#theone").click(aClick).text("Can Click!"); }); $("#unbind").click(function () { $("#theone").unbind('click', aClick).text("Does nothing..."); }); }); </script> <style> button { margin:5px; } button#theone { color:red; background:yellow; } </style> </head> <body> <button id = "theone">Does nothing...</button> <button id = "bind">Bind Click</button> <button id = "unbind">Unbind Click</button> <div style = "display:none;">Click!</div> </body> </html>
- Related Articles
- How to override jQuery event handlers?
- How to remove event handlers in JavaScript?
- How to disable some jQuery global Ajax event handlers for a request?
- How to detect all active JavaScript event handlers?
- What are event handlers in JavaScript?
- How to remove disabled attribute using jQuery?
- Example of Event Handlers in HTML5 CORS
- How to handle a link click event using jQuery?
- How to handle a double click event using jQuery?
- How to submit a form using jQuery click event?
- How to remove all style attributes using jQuery?
- How to remove all CSS classes using jQuery?
- How to remove all CSS classes using jQuery?
- How to handle a mouse right click event using jQuery?
- How to add many Event Handlers to the same element with JavaScript HTML DOM?

Advertisements