Following blocks of code are similar but have different input strings and hence different results:
// This does not change HTML
var str = "%3Cdiv%3E"; // <div>
var str_dec = decodeURIComponent(str);
console.log(str_dec); // Console output is `<div>`
document.getElementById("p1").innerHTML = "1: " + str_dec; // No HTML output
// This works fine within HTML
var str = "%3C0%3E"; // <0>
var str_dec = decodeURIComponent(str);
console.log(str_dec); // Console output is `<0>`
document.getElementById("p2").innerHTML = "2: " + str_dec; // HTML output is `<0>`
<p id="p1"></p>
<p id="p2"></p>
Although, console shows that decoding works fine in first case, why it does not appear in the HTML?
` element. From perspective here, OP is not attempting to create `<0>` element, but rather, did not inspect `.innerHTML` of `
` element following process where `
` would be present as child node of ``.