I cannot get rid of & gt; and & lt; using javascript
I raised a few questions, but I couldn't find what I wanted. So here's the code and the problem.
var cell=document.createElement('td');
cell.appendChild( document.createTextNode(unescape('Test <br>')));
alert("Content: " + cell.innerHTML);
I want to alert
display as Test <br>
, but instead it displays as Test <br>
. I've tried a lot of things like trying unescape after creating a node, trying unescape when creating a node (see above), trying to notify innerHTML
unescaped but none seem to work. No matter what I tried, I was unable to display the result as I wanted and now I need your help.
source to share
What you are doing is creating a textNode <and converting it <and> to html code. You must insert an element if you want the alert to display correctly <br>. Hope this helps you.
var cell=document.createElement('td');
var br = document.createElement('br');
cell.appendChild( document.createTextNode(unescape('Test')));
cell.appendChild(br)
alert("Content: " + cell.innerHTML);
source to share
Not sure what you really need to do innerHTML
for any reason, but if you change it to innerText
you should get the desired result.
alert("Content: " + cell.innerText);
It all seems to depend on whether you really intend to add text or want it to
be an actual line break or not. If you want it to act as a line break in you should most likely go with the Ziinloader approach.
source to share