20.9. Event Handling

One of the more powerful and often used techniques concerning JavaScript is events. Using event attributes in XHTML tags, such as onmouseover and onclick, you can create interactive documents that respond to the user's actions.

The following table lists the various events supported by JavaScript.

EventTrigger
onAbortAbort selected in browser (stop loading of image or document), usually by clicking the Stop button
onBlurWhen the object loses focus
onChangeWhen the object is changed (generally a form element)
onClickWhen the object is clicked
onDblClickWhen the object is double-clicked
onDragDropWhen an object is dropped into the user agent window (generally a file)
onErrorWhen a JavaScript error occurs (not a browser error — only JavaScript code errors will trigger this event)
onFocusWhen an object receives focus
onKeyDownWhen the user presses a key
onKeyPressWhen the user presses and/or holds down a key
onKeyUpWhen the user releases a key
onloadWhen the object is loaded into the user agent (typically used with the <body> element to run a script when the document has completed loading)
onMouseDownWhen the mouse button is depressed
onMouseMoveWhen the mouse is moved
onMouseOutWhen the mouse pointer moves outside the boundary of an object
onMouseOverWhen the mouse pointer moves within the boundary of an object
onMouseUpWhen the mouse button is released
onMoveWhen an object (generally a window or frame) is moved
onResetWhen the user selects a reset button
onResizeWhen an object (generally ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.