Skip to main content Accessibility Feedback

Event Listeners


Listen for events on an element. You can find a full list of available events on the Mozilla Developer Network.

var btn = document.querySelector('#click-me');

btn.addEventListener('click', function (event) {
	console.log(event); // The event details
	console.log(; // The clicked element
}, false);

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.