Event Handling
const button = document.querySelector('#myButton');
button.addEventListener('click', () => {
alert('Button clicked!');
});const element = document.querySelector('#myElement');
element.addEventListener('mouseover', () => {
element.style.backgroundColor = 'red';
});document.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
console.log('Enter key pressed');
}
});Last updated