0

Can you please let me know why I am not able to replace / with > in this example

var str = document.getElementById("demo").innerHTML; 
    var res = str.replace('/', ">");
    document.getElementById("demo").innerHTML = res;
<p id="demo">Change &#47;</p>

1 Answer 1

2

Because &#47; is getting translated to the real character instead (/). Try as follows:

var str = document.getElementById("demo").innerHTML; 
    var res = str.replace('/', ">");
    document.getElementById("demo").innerHTML = res;
<p id="demo">Change &#47;</p>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.