Event Handlers

Chester Wyke December 07, 2022 Updated: April 15, 2025 #javascript

OnClick

Source: https://developer.mozilla.org/en-US/docs/Web/API/Event/target

See source for more details but my understanding of it is given a function

function myOnClick(event) {
    const elementClicked = evt.target;
}

then that function can be set on any element and will fire for that element and all it’s children and the target will tell you which element (might be a child) that was clicked.