HTML currentTarget Event Property

HTMLWeb DevelopmentFront End Technology

The currentTarget event property in HTML is used to get the element whose event listeners triggered the event.

Following is the syntax −

event.currentTarget

Let us now see an example to implement the currentTarget event property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Get the element</h2>
<p onclick="myFunction(event)">Click on this line to generate an alert box displaying the element whose eventlistener triggered the event.</p>
<script>
   function myFunction(event) {
      alert("Element = "+event.currentTarget.nodeName);
   }
</script>
</body>
</html>

Output

Now double click on the line as shown in the above screenshot to generate an alert box that would display the element whose event listeners triggered the event −

raja
Published on 20-Jun-2019 10:50:43
Advertisements