index.html 662 B

12345678910111213141516171819202122
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <h2>Using the Replace Function in javascript</h2>
  5. <button onclick="myFunction()">Try it!</button>
  6. <p id="demo">Test Text</p>
  7. <script>
  8. function myFunction() {
  9. let text = document.getElementById("demo").innerHTML;
  10. /* The /i flag is a part of regular expressions and is making it so that it's case insensitive */
  11. document.getElementById("demo").innerHTML = text.replace("/MICROSOFT/i","W3Schools");
  12. /* The /g flag is a part of regular expressions and is making it so that it's global match */
  13. document.getElementById("demo").innerHTML = text.replace("/MICROSOFT/g","W3Schools");
  14. }
  15. </script>
  16. </p>
  17. </body>
  18. </html>