DEV Community

Discussion on: Understanding event.target and Use Cases

Collapse
rocktimsaikia profile image
Rocktim Saikia

So in a nutshell we can say that event.target returns a reference of the element the event was called upon and event.currentTarget returns it's parent element/container !

Collapse
dillionmegida profile image
Dillion Megida Author

You're right about event.target.

For event.currentTarget, it returns a reference to the element that fired the event.
e.g

let randomVar = document.getElementById('randomDivId');

randomVar.addEventListener("click", function(event){
  console.log(event.target, event.currentTarget);
}, false)

Same rules for event.target applies here, but as for event.currentTarget, regardless of the children of
randomDivId that you click, it will always return the randomDivId element.

Hope you get it now?

Collapse
rocktimsaikia profile image
Rocktim Saikia

That makes sense .Thanks