How to use JavaScript to replace the content of a document with JavaScript?

HTMLJavascriptProgramming Scripts

You can try to run the following code to learn how to use JavaScript to replace the content of a document in JavaScript −

Example

Live Demo
<!DOCTYPE html>
<html>
   <body>
      <p>Click and replace this content.</p>
      <button onclick = "Display()">Replace</button>
      
      <script>
         function Display() {
            document.open("text/html","replace");
            document.write("<p>Demo text!</p>");
            document.close();
         }
      </script>
      
   </body>
</html>
raja
Published on 26-Feb-2018 08:20:19
Advertisements