O'Reilly logo

Ajax: The Definitive Guide by Anthony T. Holdener III

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Events in the DOM

The ability to manipulate events on the client is central to Web 2.0 and Ajax web applications. Whether it is a user moving the mouse over an object on the application, or typing some text, or clicking on a button, the events that fire from these actions are paramount to having any client-application interaction. All client events are broken out by Event modules. These modules are as follows:

HTMLEvent module

abort, blur, change, error, focus, load, reset, resize, scroll, select, submit, unload

UIEvent module

DOMActivate, DOMFocusIn, DOMFocusOut, keydown, keypress, keyup

MouseEvent module

click, mousedown, mousemove, mouseout, mouseover, mouseup

MutationEvent module

DOMAttrModified, DOMNodeInserted, DOMNodeRemoved, DOMCharacterDataModified, DOMNodeInsertedIntoDocument, DOMNodeRemovedFromDocument, DOMSubtreeModified

Nonstandard Event module

Nonstandard events that do not really fit in the other modules

Before you can use any of these events, you must create and initialize them. The DOM enables developers to fully manipulate an event, no matter what it is. We will look at this next.

Creating Events

You can create most events by simply attaching the function or JavaScript action you want to fire directly to the event. Consider these examples:

<a href="/favorites/" onclick="close_all( );">My Favorites</a>

<input id="username" name="nptUsername" type="text" value=""
    onblur="check_user(this);" />

<body onload="initialize( );">

If, however, you need to synthesize an event from within ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required