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.
randomDivId
Hope you get it now?
That makes sense .Thanks
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You're right about event.target.
For event.currentTarget, it returns a reference to the element that fired the event.
e.g
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 therandomDivId
element.Hope you get it now?
That makes sense .Thanks