javascript replace text in element code example
Example 1: change text of element js
document.getElementById("p1").innerHTML = "New text!";
Example 2: javacsript update text in span
document.getElementById("myspan").textContent="newtext";
Example 3: javascript replace string
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
//res = Javscript replace method success
Example 4: javascript replace text within dom
document.body.innerHTML = document.body.innerHTML.replace('hello', 'hi');