Éric Viala
Éric Viala

Reputation: 626

Value of 'this' inside a mouse event handler

I was struggling a bit to handle the mouseout event on a div with a bunch of nested elements. I found this answer, which helped me, but leaves me with a further question.

The proposed answser uses this in the event handler and as far as I could test it effectively points to the element to which the handler was originally attached, and not its descendants.

My question is : is that documented somewhere ? I can't seem to find it on MDN.

Upvotes: 0

Views: 147

Answers (1)

Cheng.Lee
Cheng.Lee

Reputation: 186

Is this document?

About the handle function :

As a DOM event handler
When a function is used as an event handler, its this is set to the element the event fired from (some browsers do not follow this convention for listeners added dynamically with methods other than addEventListener).

Upvotes: 2

Related Questions