Events are actions that can be detected by JavaScript, such as clicks or key presses.
Add an event listener to an element to respond to events:
document.getElementById("myButton").addEventListener("click", function() {
alert("Button was clicked!");
});
click
- When an element is clickedmouseover
- When the mouse hovers over an elementkeyup
- When a key is releasedCreate an input field and button. When the button is clicked, display an alert with the input's value.
Answers: An action like a click; addEventListener
; detects clicks.