JavaScript - write() method

revision:


Category : document

The document.write() method writes a string of text to a document stream opened by document.open().

Use of the document.write() method is strongly discouraged.

Syntax :

        document.write(exp1, exp2, ..., expN)
    

Parameters:

exp1, ... : optional. The output stream. Multiple arguments are appended to the document in order of occurrence.

Examples:

            <body onload="newContent();">
                <p>Some original document content.</p>
            </body>
            <script>
                function newContent() {
                document.open();
                document.write("<h1>Out with the old, in with the new!</h1>");
                document.close();
                }
            </script>
            document.write("Hello World!");
            document.write("<h2>Hello World!</h2><p>Have a nice day!</p>");
            document.write(Date());
        

Practical examples

example:
code:
                    
                

example:
code:
                    
                

example:
code: