What is event.target?

In simplest terms, the event.target is the element on which the event occurred or the element that triggered the event.

Sample HTML Markup.

<div onclick="clickFunc(event)">
<div>
<div>
<button>Button</button>
</div>
</div>
</div>

Sample JavaScript.

function clickFunc(event) {
console.log(event.target);
}

If you click the button it will log the button markup even though we attach the event on the outermost div it will always log the button so we can conclude that the event.target is the element that triggered the event.


Author of content
Edit this page

Made by Michael Sakhniuk

Twitter