javaScript output

javascript is typically used to manipulate html elements.


the javascript document write function

the javascript document.write() function is used to write something into the page when the page is first created.the document.write() function only work with pages that the browser processes as html.

the example below writes a <h1> and <p> element directly into the html document output:

 <!doctype  html>

    <html>
          
       <body>
             
                  
        <script>
                    
    document.write("<h1> this is the script h1 element output</h1>");
                         
    document.write("<p> simple paragraph tag output by the javascript</p>");
                         
      </script>
                
  </body>
             
</html>

note: if you execute document.write after the document has finished loading,the complete <html> web page will be overwritten:

 <!doctype  html>

    <html>
          
       <body>
             
            <h2>this is demo for simple javascript output</h2>
            
            <button    onclick = "demo()"> please click it </button>
                  
        <script>
        
    function   demo(){     
                    
    document.write("<h1> document write function is used for output </h1>");
                         
    document.write("<p>  what is the document write function </p>");
    
    }
                         
      </script>
                
  </body>
             
</html>