DOM, Dynamic, Explore, Inspect, Interrogate, Investigate, Presentation, Render, Snapshot, State, View, Visualise, Visualize
Devi keeps banging on the Clear button, but the document text remains stubbornly unaffected. She fires up a DOM Inspection tool, and discovers that the button's onclick event handler isn't present, which would explain why nothing was happening.
How can you inspect the DOM's state at any time, taking into account DOM manipulations since the page was loaded?
Use a DOM Inspection Tool to explore the dynamic DOM state. The initial HTML for an Ajax App is often minimal, and in any event likely to change over time due to DOM Manipulation. A DOM Inspection tools traverses the browser's current DOM model, rather than the initial HTML source, to build up a presentation of the current DOM. Many times, the tool is interactive, allowing you to drill down the hierarchy, search for keywords, and so on. All this is very useful for checking assumptions and diagnosing problems, since many Ajax bugs arise because the programmer misunderstood the DOM state at a particular time.
Incidentally, DOM inspection is useful beyond the fact that the DOM is dynamic. Even for static applications, an interactive exploration tool is often a good complement to the pile of text that makes up a complex HTML document.
Firefox ships with a DOM Inspector tool, accessible from the tools menu (Figure 1.103, “Firefox DOM Inspector”). The inspector is a popup window, showing the DOM hierarchy on one side, facing a summary of the selected node. The summary shows node attributes such as registered event handles, as well as CSS style information.
Chris Pederick's Web Developer extension is an invaluable Firefox toolbar for web development (Figure 1.104, “webdevtoolbar”). Among its vast feature set are several commands especially relevant to DOM Inspection:
Display commands augment the page with DOM information, which makes a great alternative to exploring the DOM in a completely separate view. For example, Display Topographic Information alters the page to reveal the layout of DOM elements and Display ID and Class Details augments each element with its id and class attributes.
Outline commands draw outlines around elements of a particular type. For example, Outline Block Level Elements or Outline Table Cells. In fact, you can define custom outlines to outline any element you want.
Form commands help expose form structure. Display Form Details augments the form with information about each control, while View Form Information opens up a summary page.
Jennifer Madden's View Rendered Source is a Firefox extension that shows the entire DOM as an HTML document (Figure 1.105, “View Rendered Source”). Note that this is not the same thing as the good old View Source feature, because the rendered source reflects the DOM after any manipulation has taken place. The rendered source is shown in a pretty-formatted style, using colours and spacing to help convey the DOM structure. This is a free tool and there's also a slightly enhanced version that can be purchased for a small fee.
Microsoft's free IE Developer Toolbar for IE6+ has a number of DOM Inspection capabilities and is similar to the Firefox Web Developer Extension (Figure 1.106, “IE Toolbar”). It also includes a DOM explorer similar to Firefox's DOM inspector (Figure 1.107, “IE DOM Explorer”).
You can find a list of IE DOM Inspectors at
Tim Tabor's IEDocMon is an open-source tool that extends IE to include an interactive view of the DOM.
Steven Chipman's Mouseover DOM Inspector is a convenient bookmarklet that lets you explore the DOM by mousing over page elements. It works on all recent browsers except Safari.