tezvyn:

What is the click event's type and how to reference the button?

Source: developer.mozilla.orgbeginner

WHAT IT TESTS: DOM event inheritance and currentTarget versus target. ANSWER OUTLINE: Handler receives a MouseEvent. Use event.currentTarget for the attached button, since event.target may be a nested child.

WHAT IT TESTS: Whether you understand DOM event hierarchy and the fired element versus the listener owner. ANSWER OUTLINE: First, the type is MouseEvent, inheriting from UIEvent then Event. Second, use event.currentTarget for the attached button, since it always points to the listener's element. Third, event.target is unreliable because it returns the deepest clicked element, such as a nested icon. RED FLAG: Answering Event or UIEvent, or suggesting event.target or this without currentTarget.

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is the click event's type and how to reference the button? · Tezvyn