2021-07-01 17:19:32 -04:00

32 lines
960 B
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html>
<head>
    <title>Complete JavaScript Course</title>
</head>
<body>
    <div id="output">Complete JavaScript Course</div>
Search for :
    <input id="sText" type="text">
    <br> Replace with :
    <input id="rText" type="text">
    <br>
    <button>Replace</button>>
<script>
const output = document.getElementById('output')
const findValue = document.getElementById('sText');
const replaceValue = document.getElementById('rText');
document.querySelector("button").addEventListener("click", lookUp);
function lookUp() {
const s = output.textContent;
const rt = replaceValue.value;
const re = new RegExp(findValue.value, "gi");
if (s.match(re)) {
let newValue = s.replace(re, rt);
output.textContent = newValue;
}
}
</script>
</body>
</html>