Javascript DOM Event currentTarget Property

Introduction

Get the element whose event listeners triggered a specific event.

The currentTarget property does not necessarily return the element that was clicked on, but the element whose event listener triggered the event.

View in separate window

<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">
<script>
function myFunction(event) {/*w ww  . ja  va 2 s.c  o  m*/
    document.getElementById("demo").innerHTML = event.currentTarget.nodeName;
}
</script>
<p id="demo"></p>
</body>
</html>

The currentTarget event property returns the element whose event listeners triggered the event.

The currentTarget property refers to the element whose event listener triggered the event, opposed to the target property, which returns the element that triggered the event.




PreviousNext

Related