DEV Community

Discussion on: Understanding event.target and Use Cases

Collapse
 
dillionmegida profile image
Dillion Megida

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