Answer the question
In order to leave comments, you need to log in
Finding changes in text?
How to find changes in text using pure JS?
For example, initially the text was: "Text before change", and after that it became "Text after change". The script will highlight only "before"
Answer the question
In order to leave comments, you need to log in
<span>
<input id="textarea_1" type="text" placeholder="до">
<input id="textarea_2" type="text" placeholder="после">
<p id="textarea_after"> </p>
</span>
<button id="button">найти</button>
button.onclick = () => {
textarea_after.textContent = findChanged(textarea_1.value,textarea_2.value)
}
function findChanged (orig,changed) {
[orig,changed] = [orig,changed].map((text) => text.split(""))
return changed.filter( (char) => orig.indexOf(char) === -1 ).join("")
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question