- 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 override jQuery event handlers?
Use the off() method to override jQuery event handlers. This method is used to remove an event handler. The on() method is used to attach one or more event handler.
Example
You can try to run the following code to learn how to override jQuery event handlers −
<html> <head> <title>jQuery off() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { function aClick() { $("div").show().fadeOut("slow"); } $("#bind").click(function () { $("#theone").on("click", aClick).text("Can Click!"); }); $("#unbind").click(function () { $("#theone").off("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 remove event handlers using jQuery?
- How to disable some jQuery global Ajax event handlers for a request?
- How to remove event handlers in JavaScript?
- How to detect all active JavaScript event handlers?
- What are event handlers in JavaScript?
- Example of Event Handlers in HTML5 CORS
- How to add many Event Handlers to the same element with JavaScript HTML DOM?
- How to suppress jQuery event handling temporarily?
- How to handle jQuery AJAX success event?
- How does jQuery event namespace works?
- How to handle a link click event using jQuery?
- How to handle a double click event using jQuery?
- How to debug JavaScript/jQuery event bindings with Firebug?
- How to return variable value from jQuery event function?
- How to submit a form using jQuery click event?

Advertisements