What is event.currentTarget?

The event.currentTarget is the element on which we attach the event handler explicitly.

Copying the markup from previous Question. Sample HTML Markup.

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

And changing our the JS a little bit.

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

If you click the button it will log the outermost div markup even though we click the button. In this example, we can conclude that the event.currentTarget is the element on which we attach the event handler.


Made in India with ❤️ by Rajesh Kumar Yadav

Twitter