frank astin
frank astin

Reputation: 109

Javascript get element which handler was attached to

When an onclick event is fired on a element how do you get the element the event was attached to from the event object (opposed to the .target element that was clicked on)?

Upvotes: 3

Views: 79

Answers (1)

Josh Crozier
Josh Crozier

Reputation: 241118

You could access the currentTarget property instead.

From MDN :

currentTarget - Identifies the current target for the event, as the event traverses the DOM. It always refers to the element the event handler has been attached to as opposed to event.target which identifies the element on which the event occurred.

Upvotes: 2

Related Questions