target Event Property - Javascript DOM

Javascript examples for DOM:Event

Description

The target event property returns the element that triggered the event.

Return Value

A reference to the object on which the event originally occured

The following code shows how to get the element that triggered a specific event:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">

<p>Click here.</p>

<script>
function myFunction(event) {//from w ww. j  av a  2  s. c  om
    console.log(event.target.nodeName);
}
</script>

</body>
</html>

Related Tutorials