Chapter ONLINE SECTION IV. Changing Page Content and Styles

As the name “Dynamic HTML” implies, the technology allows page authors to change HTML markup after the page has loaded from the server. Prior to the Version 4 browsers, your ability to script dynamic content was limited to controlling the HTML being written to the current page as the page initially loaded, loading HTML documents into other frames, altering form controls, and, in some browser versions, swapping same-size images. But when browsers such as IE 4 (and later), Mozilla-based browsers, and Safari expose every HTML element to a scriptable object model and automatically reflow pages, authors gain extraordinary powers to change anything on the page at any time.

This chapter provides an overview of the most common ways of dynamically changing content, including some techniques that work with older browsers. It also offers suggestions about how to develop code that accommodates the incompatibilities that exist between the IE-only and W3C DOMs. Compared to the contortions necessary in the IE 4 versus Netscape Navigator 4 days, most cross-browser dynamic content tasks today are a breeze.

Writing Variable Content

While a page is loading, you can use the JavaScript document.write( ) or document.writeln( ) methods to fill in content that cannot be stored as part of the document. Example IV-1 demonstrates a simple combination of hardwired HTML with dynamically written content to fill a page. In this case, the dynamically written ...

Get Dynamic HTML: The Definitive Reference, 3rd Edition 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.