What is Unobtrusive JavaScript and DOM Scripting?
Rather than hardcoding event handlers as HTML attributes, unobtrusive JavaScript assigns them using the DOM. Well-structured, valid HTML is a prerequisite to DOM scripting. Documents should declare a DOCTYPE, they should validate against the DOCTYPE, and presentational styles should be applied with CSS (read “should” as “life will be easier for everyone if you do”). Use a few targeted CSS ID and class selectors to define page layout. Don’t go overboard on defining selectors, remember, descendent selectors are your friend. I’ll use a simple text-based rollover for demonstration purposes. In a perfect world, with perfect browsers, this effect would be created using the CSS pseudo hover class but, as you’ve probably guessed, it doesn’t work in Internet Explorer 6. Here’s a screenshot of what we’re building.