How to replace the content of an HTML document in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
<body>

<p>Text Text Text</p>

<button onclick="ReplaceContent()">Replace Content</button>

<script>
function ReplaceContent() {
  document.open("text/html","replace");
  document.write("<h1>Title H1</h1>");
  document.write("<p>Paragraph P</p>");
  document.body.style.backgroundColor = "white";
  document.close();
}
</script>

</body>
</html>

 



answered Jan 11, 2019 by avibootz

Related questions

...