jQuery event.namespace Property


The event.namespace property in jQuery is used to return the custom namespace when the event was triggered.

Syntax

The syntax is as follows −

event.namespace

Example

Let us now see an example to implement the jQuery event.namespace property −

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("p").on("custom.demoNamespace",function(event){
         alert(event.namespace);
      });
      $("p").click(function(event){
         $(this).trigger("custom.demoNamespace");
      });
      $("button").click(function(){
         $("p").off("custom.demoNamespace");
      });
   });
</script>
</head>
<body>
<h2>Demo Heading</h2>
<p>This is demo paragraph.</p>
<p>This is demo paragraph.</p>
<button>Remove namespace</button>
<p>Click on any of the above paragraph</p>
</body>
</html>

Output

This will produce the following output −

Above, on clicking any of the p element −

Now, click the button “Remove Namespace”. After that, on clicking any of the p element, none of the alert box will generate.

Updated on: 11-Nov-2019

95 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements