/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Sometimes, setting an element attribute (e.g., title) with javascript automatically escapes all amphersands in the // string, apparently to be "helpful". It also does this when creating a text node with document.createTextNode. //This function gets around this by setting innerHTML on a temporary element and returning the text node's value. function literalText(str) { var tmp = document.createElement("div"); tmp.innerHTML = str; return (tmp.firstChild ? tmp.firstChild.nodeValue : ""); }
Comments
