I just started learning javascript from w3school , and I found that "you can use document.write only for HTML output. If you use it after loading the document, the whole document will be overwritten." so I tried to write the following code to validate:
<html> <head> <title>ashish javascript learning</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <p> sample html with javascript </p> <script> document.write("<h1>this is heading</h1>"); document.write("<p>this is sample para</p>"); </script> <script> if(document.readyState === "complete"){ loaded(); } function loaded(){ document.write("<p>loading content after the document has been loaded"); } </script> </body> </html>
The code still shows the old value and does not overwrite the contents of the web page. Could you suggest me what I am doing wrong.
source share