Skip to content

Event Handler Context

In DOM event handlers, this refers to the element that received the event (unless using arrow functions or explicit binding).

button.addEventListener("click", function () {
console.log(this); // the button element
});