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
...
<BODY>
Regular HTML
						<SCRIPT TYPE="text/javascript">
						<!--
						Build HTML Here
						// -->
						</SCRIPT>
						More Regular HTML
</BODY>

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