jQuery event.type property with Example


The event.type property in jQuery is used to return which event type was triggered.

Syntax

The syntax is as follows −

event.type

Example

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

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      color: blue;
      background-color: orange;
   }
   .test {
      color: white;
      background-color: black;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("p").on("click dblclick mouseover",function(event){
         $("div").html(event.type+" event");
      });
   });
</script>
</head>
<body>
<h2>Heading Two</h2>
<p class="demo">Click here and let's see whether it was a click, double click or mouseover</p>
<div class="test"/>
</body>
</html>

Output

This will produce the following output −

Now, keep the cursor on the <p> element text and let’s see which event that would be −

Now, double click on the <p> element text and let’s see what event would be visible −

Updated on: 12-Nov-2019

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements