Sudhanshu Saini Sudhanshu Saini - 4 months ago 11
Javascript Question

How to add special character using javascript

I want to insert a special character dynamically using javascript

₹25



<div class="price"><span>&#8377;</span>25</div>





I want to replace above code..here is what i have coded:



var main = document.createElement('div');
main.className = "price";
var abc = document.createElement('span');
var t = document.createTextNode("&#8377;");
abc.appendChild(t);
main.appendChild(abc);
var t1 = document.createTextNode("25");
document.body.appendChild(main);





How to show this special character?

Answer

var main = document.createElement('div');
main.className = "price";
var abc = document.createElement('span');
abc.innerHTML="&#8377;";
main.appendChild(abc);
var t1 = document.createTextNode("25"); 
main.appendChild(t1);
document.body.appendChild(main);