JavaScript: DOM Events

By Xah Lee. Date:

this page is a short intro on DOM event object. For basics of how to use event, see:

event Properties


write about stopPropagation

button.addEventListener ("click", function(e){
/* ... */
}, false);

write about stopPropagation

ou can prevent the default action with the preventDefault() function on the event object. Alternatively, you can just return false from the handler:

form.addEventListener ("submit", function(e){
/* ... */
return confirm("Are you super sure?");
}, false);

If the call to confirm() returns false—

write about The Event Object

when a event is fired, its event handler is passed a event object.

modern browsers support this object, except IE8 and below


keyboard event Properties

Elements associated with the event:

JS in Depth