jQuery event.namespace Property

Introduction

Add and remove a custom namespace:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from www  . j av a 2 s  .c  om
<script>
$(document).ready(function(){
  $("p").on("custom.someNamespace",function(event){
    alert(event.namespace);
  });
  $("p").click(function(event){
    $(this).trigger("custom.someNamespace");
  });
  $("button").click(function(){
    $("p").off("custom.someNamespace");
  });
});
</script>
</head>
<body>

<p>Click on this paragraph.</p>

<button>Remove namespace</button>

</body>
</html>

The event.namespace property returns the event namespace.

Namespaces beginning with an underscore are reserved for jQuery.

event.namespace
Parameter Optional Description
event Required. The event parameter comes from the event binding function



PreviousNext

Related