jQuery event.currentTarget Property

Introduction

event.currentTarget is typically equal to this:

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   w w  w  .j  a v  a2s.c  om
<script>
$(document).ready(function(){
  $("h1, h2, p").click(function(event){
     document.getElementById("demo").innerHTML = 
            event.currentTarget === this;
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<h1>Heading 1</h1>
<h2>Heading 2</h2>

<p>Click on each HTML element. 
The currentTarget is typically equal to "this", and will return "true".
</p>

</body>
</html>

The event.currentTarget property is the current DOM element within the event bubbling phase.

The event.currentTarget property is typically equal to this.

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



PreviousNext

Related