Javascript DOM Event target Property

Introduction

Get the element that triggered a specific event:

The target property returns the element that triggered the event, and not necessarily the eventlistener's element.

View in separate window

<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">
<p id="demo"></p>
<script>
function myFunction(event) {/*from  w  w  w  .j  a v a2 s  . c o  m*/
  document.getElementById("demo").innerHTML = event.target.nodeName;
}
</script>

</body>
</html>

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




PreviousNext

Related