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.
October 30, 2022
1455
Read more
What is the JavaScript += Operator and How Do You Use It?
December 04, 2022
JavaScriptUsing the startsWith() Method in JavaScript
December 04, 2022
JavaScriptReverse a String in JavaScript: 2 Easy Methods
December 02, 2022
JavaScript