I’m trying to replace the square root symbol which is written in html as “√” (
I used the following line to replace it with a space but it does not change the String at all.
dig = document.getElementById("dig").innerHTML; dig = dig.replace(/'√'/g, ' '); console.log(dig);
What am I doing wrong here?
This answer is valid if you are accessing the
innerHTML atribute of an
let s = document.getElementById("sqrt") console.log("Text", s.innerText) console.log(s.innerText.replace(/√/g, "")) console.log(s.innerHTML.replace(/√/g, ""))
<div id="sqrt"> √2 == 1.4142</div>
As you can see
√ gets evaluated and it’s value is then
replace method cannot understand that
&radic so you can just replace
Also there is no need to use regex, you can just do the same with