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>

asked Jul 3, 2015 at 18:09

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>

answered Jul 3, 2015 at 18:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.