Skip to content
Related Articles

Related Articles

HTML | DOM target Event Property

View Discussion
Improve Article
Save Article
  • Last Updated : 11 Jul, 2022
View Discussion
Improve Article
Save Article

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!