Javascript Data Type How to - Replace all text on web page








Question

We would like to know how to replace all text on web page.

Answer


<!DOCTYPE html>
<html>
<body>
<!--  ww  w  .jav a  2  s  . co  m-->
  <p>
    Hello <a href="#">Hello <span>Hello</a></a>
  </p>
<script type='text/javascript'>

document.body.innerHTML= document.body.innerHTML.replace(/Hello/g, "HELLO");

</script>
</body>
</html>

The code above is rendered as follows: