HTML | DOM target Event Property

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

  • Google Chrome
  • Internet Explorer 9.0
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.