Olav Junker Kjær takes us through how browser-based JavaScript deals with events and default action, including the dispatch sequence of events, when they are bubbled and captured and the order of these events. Also shows some setTimeout() tricks to deal with long-running JavaScript
PPK describes the this keyword as a reference to the owner of the function we are executing, or the object that a function is a method of. He then compares how attaching a function to an event in two different ways affects what the this keyword references.
Andy Hume whittles away the various JavaScript libraries to produce a clear explanation of event delegation and how it works. Its a technique that reduces the number of event listeners attached to the document by attaching just one event listener to a container element. He presents a simple code example and talks about the benefits of event delegation, including performance and code maintenance. (Includes workarounds for IE and a Safari bug)
Tim Huegdon uses JavaScript to fix Safari's bug where clicking on a label doesn't set focus to the corresponding field element (a useful accessibility aid). Using YUI and event delegation Tim walks us through the development of this piece of code involving attaching an event listener, getting the target of an event, then finding the field that corresponds to the label, and focusing on it if its a text field, or activating / selecting the form element if its a radio button or checkbox.
Simon Willison blogs about how JQuery won him over. From its faddish start based around CSS selectors (getElementsBySelector), and method chaining, Simon now sees the library in a new light. Simon shows how jQuery supports modern development best practice such as namespaces, giving a quick nod to the richness of jQuery selectors (DOM, CSS and XPath). JQuery's event handling looks natural and offers an event when the dom is ready. It exposes custom events for non-trivial Ajax requests. Simon's so convinced about jQuery that he's willing to overlook his rule that developers should know how a library works before using it.
Jack Slocum presents a simple recipe to avoid memory leaks, including setting onreadystatechange to null on completion of an XMLHttpRequest, clean up DOM Event handlers on unload, never put non-primitives into a DOM node.
Christian Heilmann describes an approach to building complex web application by basing them around events, particularly around YUI's CustomEvent class.
Christian Heilmann's excellent guide to writing unobtrusive JavaScript. Takes the reader from the inline JavaScript world right through to a clean dynamically attached events with all the JavaScript code in external files. Covers DOM Scripting. This is the key reference to unobtrusive scripting.
Christian Heilmann does a tree menu without using loops. It demonstrates the flexibility and power of Event delegation - catching events at a higher level in the document. It drastically cuts down on the number of events you need to add to a document. One event handler per menu, rather than one per link in the menu.
Christian Heilmann demonstrates delegating events, and compares it to the main alternative of assigning event handlers to each individual node. Its a technique that's important for writing applications that can scale.
Dean Edwards presents his improvement to Scott Andrews' famous addEvent()
functions. Solving the cross-browser this
reference differences, and passing event
objects correctly.