- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 would you unbind all jQuery events from a particular namespace?
To unbind jQuery events from a particular namespace, use the unbind() method. The event.namespace property is used to return the custom namespace when the event was triggered.
Example
You can try to run the following code to learn how event namespace works and how you can unbind the jQuery events from a namespace −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").on("custom.myNamespace",function(event){ alert(event.namespace); }); $("p").click(function(event){ $(this).trigger("custom.myNamespace"); }); $("button").click(function(){ $("p").off("custom.myNamespace"); }); }); </script> </head> <body> <p>Click me</p> <button>Click the button to remove namespace.</button> <p>Clicking the above button removes the namespace.</p> </body> </html>
Advertisements