Chapter 5: document.write() and writeln()

355 8 0
                                    

Document.write is an easy-to-learn line that can be useful if there is a page error of some kind.
This is like the alert or console.log, but will erase everything on the page, and write the value you put in the document.write().
Since you obviously have a knowledge of HTML, (I hope), you can put HTML elements into the document.write
Say you wanted to make a new paragraph, you can do,
document.write("<p>New paragraph that we all love</p>");
But there is only one problem with this, this will clear the page, then make the paragraph. But what we want to do is make a new paragraph on the document, so what you can do, is type
document.writeln("<p>A new paragraph that doesn't erase the whole page!");

JavaScript for NewbiesWhere stories live. Discover now