document.writeln

In this chapter you will learn:

  1. How to append content the end of a HTML document
  2. How to use document.writeln() to output HTML tags

Append to the end

document.writeln() appends content to the end of the HTML document.

<!DOCTYPE HTML> <!--   ja  v a  2s. c  o m-->
<html> 
    <body> 
        <p> 
            This is a test.
        </p> 
        <script> 
              document.writeln("new added");
            
        </script> 
    </body> 
</html>

Click to view the demo

Output tags

The following code uses document.writeln() to append tags.

<!DOCTYPE HTML> <!--   ja v  a2 s  .c o  m-->
<html> 
    <body> 
        <p id="myText"> 
            <span id="mySpan">HTML</span> 
            This is a test.
            This is a test.
        </p> 

        <script> 
              document.writeln("<pre>J ava 2s .com</pre>");
            
        </script> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. What is DOM
Home » Javascript Tutorial » Document
Document Object
document.body
document.characterSet
document.charset
document.compatMode
document.cookie
document.defaultCharset
document.defaultView
getElementsByTagName(tagName)
document.getElementsByClassName
document.getElementsByName
document.images
document.lastModified
document.location
document.implementation
document.querySelectorAll
document.readyState
document.title
document.URL
document.writeln