
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 jQuery Event Namespace Works
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 to create and remove 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> <p>Click above to generate an alert box. Click the below button to remove namespace, which won’t generate an alert box.</p> <button>Click this button to remove namespace.</button> </body> </html>
Advertisements