HomeMathComputingArtsWordsLiteratureMusictwitter facebook webfeed

Generating HTML Content With Javascript

Advertise Here For Profit

Xah Lee, 2005-05

This page shows a javascript example of generating HTML content dynamically using document.write. If you are not familiar with js, see: Javascript Basics.

The following code prints out numbers from 1 to 9 directly into the page where the js code is:

document.write("<p>");
for (var i=1; i< 10; i++) { document.write(i + " "); }
document.write("<\/p>");

This is a simple example of inserting text into a document. But this is not a good way. Because html is not plain text, but a tree. For a much better way, see: Inserting HTML Content With Javascript.

blog comments powered by Disqus