prevent escaping special characters on textnode(JS-HTML)
Posted
by UnLoCo
on Stack Overflow
See other posts from Stack Overflow
or by UnLoCo
Published on 2010-04-01T14:52:23Z
Indexed on
2010/04/01
15:03 UTC
Read the original article
Hit count: 292
Hello
i followed this snippet http://bytes.com/topic/javascript/answers/504399-get-all-text-nodes
var xPathResult = document.evaluate(
'.//text()[normalize-space(.) != ""]',
document.body, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null ); for (var i = 0, l = xPathResult.snapshotLength; i < l; i++) {
var textNode = xPathResult.snapshotItem(i);
textNode.data = textNode.data.replace(/somePattern/g, 'replacement');
}
i want to replace certain patterns like for example |12|
with a corresponding emoticon !
but when i do textNode.data.replace("|12|",'<.img src="favicon.ico"/>');
for example
the text show is ..<.img src="favicon.ico"/>..
as i inspect the html i find that <.img src="favicon.ico"/>
became escaped to <img src="favicon.ico"/>
is it possible to prevent this and to let the image show ??
Thank You
Note: added extra point here <.img src="favicon.ico"/>
in purpose
© Stack Overflow or respective owner