Created
October 9, 2025 06:38
-
-
Save gbowne1/50d109be058f79b18b3660fe2d5e926f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The addEventListener() method in JavaScript is used to attach an event handler to a specified element in the Document Object Model (DOM). It takes three parameters: | |
| • target: This is the DOM object (element, document, window, etc.) to which the event listener is attached. Examples include: | |
| • HTML elements (e.g., document.getElementById('myButton'), document.querySelector('div')) | |
| • The document object | |
| • The window object | |
| • event: This is a string representing the name of the event to listen for. Common event types include: | |
| • Mouse Events: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, contextmenu | |
| • Keyboard Events: keydown, keyup, keypress | |
| • Form Events: submit, reset, change, input, focus, blur | |
| • Window Events: load, resize, scroll, unload | |
| • Clipboard Events: copy, cut, paste | |
| • Drag and Drop Events: dragstart, drag, dragenter, dragleave, dragover, drop, dragend | |
| • Media Events: play, pause, ended, volumechange, timeupdate | |
| • Touch Events: touchstart, touchend, touchmove, touchcancel | |
| • listener (function): This is the function that will be executed when the specified event occurs on the target element. This function is often referred to as the "event handler." | |
| • useCapture (optional): This is a boolean value (true or false) that specifies whether the event listener should be executed in the capturing phase or the bubbling phase of event propagation. false (default) means bubbling, true means capturing. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment