I got a situation where I have to replace a HTML text in production environment, which is getting generated dynamically from back-end C# code and I have to do this without rebuilding and redeploying the dlls.
I need to replace a heading which is in <h2>...</h2>tag:
<h2>Test - 1</h2>
<h2>Test - 2</h2>
<h2>Test - 3</h2>
var string = document.getElementsByTagName("h2").innerHTML;
var replacedString = string.replace("Test - 3", "Test - 5");
document.getElementsByTagName("h2").innerHTML = replacedString;
This can also be accomplished alternatively by going through all the <h2> elements one by one and replace the matching text using an if condition.