Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM target Event Property

  • Last Updated : 27 Aug, 2019

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

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

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:




<!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
  • Internet Explorer 9.0
  • Firefox
  • Safari
  • Opera



My Personal Notes arrow_drop_up
Recommended Articles
Page :