Event Listeners

Estimated reading: 1 minute 55 views
				
					addEventListener()
				
			

The addEventListener() method is used to attach an event handler to an HTML element. It takes two parameters: the event type and the function to be executed when the event occurs.

				
					element.addEventListener(event, function, useCapture);

				
			
				
					const button = document.getElementById('myButton');

function handleClick() {
    console.log('Button clicked!');
}

button.addEventListener('click', handleClick);

				
			
Share this Doc

Event Listeners

Or copy link