Open In App

HTML | DOM target Event Property

Last Updated : 11 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The target event property in HTML DOM is used to return the element that triggered the event. 

Syntax:

event.target

Return Value: This property returns the reference of the object on which the event originally occurred. 

Below example illustrates the target Event Property in HTML DOM: 

Example: 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        HTML DOM target Event Property
    </title>
     
    <style>
        body {
            text-align:center;
        }
        h1 {
            color:green;
        }
    </style>
</head>
 
<body onclick="myGeeks(event)">
     
    <h1>GeeksforGeeks</h1>
     
    <h2>HTML DOM target Event Property</h2>
 
    <p>Click on the elements to get the triggered element</p>
 
    <button>Click Here</button>
 
    <p id = "GFG"></p>
     
    <script>
        function myGeeks(event) {
            var x = event.target;
             
            document.getElementById("GFG").innerHTML
                = "Triggered element: " + x.tagName;
        }
    </script>
</body>
 
</html>


Output:

  

Supported Browsers: The browsers supported by HTML DOM target Event Property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 9 and above
  • Firefox 1 and above
  • Safari 1 and above
  • Opera 7 and above


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads