I've been trying decode text, so I can take unescape JSON encoding. But I can't get to work when the variable value is innerHTML but it works when I hardcode the same string value to the variable.
innerHTML Example (I need help with)
<html>
<body>
<p id="uri">C:\\Users\\User\\Documents\\Fax</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var uri = document.getElementById("uri").innerText;
var dec = decodeURI(uri.toString());
var res = "Decoded URI: " + dec;
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
Expected Result: Decoded URI: C:\Users\User\Documents\Fax
Working example with a hardcoded value
<html>
<body>
<p id="uri">Decode</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var uri = "C:\\Users\\User\\Documents\\Fax";
var dec = decodeURI(uri.toString());
var res = "Decoded URI: " + dec;
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
Actual Result: Decoded URI: C:\Users\User\Documents\Fax
What am I doing wrong?