I would like to replace the string "Microsoft" with "W3Schools Test$".
Please note that there is single quotes after the dollar sign.
It is not working with my below code. You can see demo-one is working perfectly, but in case of demo-two its not working well.
function myFunction() {
var str_one = document.getElementById("demo-one").innerHTML;
var res_one = str_one.replace("Microsoft", "W3Schools Test$");
document.getElementById("demo-one").innerHTML = res_one;
var str_two = document.getElementById("demo-two").innerHTML;
var res_two = str_two.replace("Microsoft", "W3Schools Test$'");
document.getElementById("demo-two").innerHTML = res_two;
}
<p>Click the button to replace "Microsoft" with "W3Schools" in the paragraph below:</p>
<p id="demo-one">Visit Microsoft!</p>
<p id="demo-two">Visit Microsoft!</p>
<button onclick="myFunction()">Try it</button>
Here is the output of the above code.
Click the button to replace "Microsoft" with "W3Schools" in the paragraph below:
Visit W3Schools Test$!
Visit W3Schools Test!!
Third line should show as Visit W3Schools Test$'
but it showing as Visit W3Schools Test!!
Please help me to get out from this problem.
Thanks in advance.