Update Find and Replace text
This commit is contained in:
parent
143b56d64f
commit
59b4952d6c
@ -1,26 +1,28 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Complete JavaScript Course</title>
|
||||
<title>Complete JavaScript Course</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="output">Complete JavaScript Course</div>
|
||||
<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>>
|
||||
<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');
|
||||
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;
|
||||
@ -28,4 +30,5 @@
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user