O'Reilly logo

Dynamic HTML: The Definitive Reference, 3rd Edition by Danny Goodman

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

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 ...

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