JAVASCRIPT Tutorial
event.target
identifies the HTML element that triggered the event.event.type
indicates the type of event that occurred (e.g., "click", "mouseover").event.preventDefault()
prevents the browser's default behavior for the event (e.g., opening a link).event.stopPropagation()
prevents the event from bubbling up to parent elements.event.clientX
/event.clientY
: Mouse cursor position in the page.event.keyCode
: Key pressed, if relevant.event.ctrlKey
/event.shiftKey
/event.altKey
: Modifier keys pressed.// Event listener for a button click
document.querySelector('button').addEventListener('click', (event) => {
console.log(event.type); // "click"
console.log(event.target); // Button element
event.preventDefault(); // Prevent the page from reloading
});
event.target.tagName
to identify the type of element that triggered the event.event.target.closest()
to identify a parent element, if necessary.e
as the parameter name for the event object, as it's commonly used in English and may not be accessible to screen readers.