24.1. Generating HTML Dynamically

JavaScript code contained inside a SCRIPT element is executed as the page is loaded, with any output the code generates being inserted into the document at the place the SCRIPT occurred. Listing 24.1 outlines the basic format. Don't worry about all the syntactic details for now; we explain them at the end of this section. For now, just note the standard form.

Listing 24.1. Template for Generating HTML with JavaScript
Regular HTML
						<SCRIPT TYPE="text/javascript">
						Build HTML Here
						// -->
						More Regular HTML

You can also use the SRC attribute of SCRIPT to load remote JavaScript code.

The simplest way to build HTML is to use document.write, which places a single string in the current ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.