This page shows a JavaScript example of generating HTML content dynamically using document.write.
The following code prints out numbers from 1 to 9 directly into the page where the JavaScript 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: JavaScript: Insert HTML Element Example.
blog comments powered by Disqus