Chapter 7. Creating Markup on the Fly

What this chapter covers:

  • A quick look at the "old-school" techniques: document.write and innerHTML

  • An in-depth look at the DOM methods createElement, createTextNode, appendChild, and insertBefore

  • An introduction to Ajax and asynchronous requests

Most of the DOM methods you've seen so far are useful for identifying elements. Both getElementById and getElementsByTagName allow you to quickly and easily target specific element nodes in a document. These elements can then be manipulated using methods and properties like setAttribute (to change the value of an attribute) or nodeValue (to change the text contained by an element node). That's how the image gallery works. The showPic function identifies two elements, ...

Get DOM Scripting: Web Design with JavaScript and the Document Object Model, Second 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.