Skip to content
Related Articles

Related Articles

Improve Article

How to check whether the event namespace is used in jQuery ?

  • Last Updated : 21 Jun, 2021
Geek Week

The jQuery is lightweight, and it has a lot of features like HTML/DOM manipulation, CSS manipulation, HTML event methods, effects and animations, AJAX, utilities. Many multinational companies like Google, IBM, and Microsoft use the jQuery library in their application.

The event.namespace property returns the custom namespace when the event was triggered. This property will be used primarily by plugin authors who want to handle tasks differently depending on the event namespace used.

Example: Below is the HTML code for determining the event namespace used.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8" />
    <script src=
    </script>
</head>
  
<body>
    <h2 style="color: green">GeeksforGeeks</h2>
    <button>Click here</button>
    <div style="height: 10px"></div>
    <div id="showEventNamespace"></div>
  
    <script>
  
        // Attach one or more event using .on() method
        $("#showEventNamespace").on(
            "test.GeeksForGeeksEventNamespace",
            function (event) {
  
                // event.namespace message is
                // shown in the div
                $("#showEventNamespace").show()
                    .html(event.namespace);
            }
        );
  
        // On click of the button, the event
        // namespace is triggered
        $("button").click(function (event) {
            $("#showEventNamespace")
                .trigger("test.GeeksForGeeksEventNamespace");
        });
    </script>
</body>
  
</html>

Output:

event.namespace

Note: The namespace starting with an underscore are reserved for jQuery.




My Personal Notes arrow_drop_up
Recommended Articles
Page :