Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<title>createTextNode example</title>
<script type="text/javascript">
var text = "&lt;img src='http://www.spam.com/assets/images/backgrounds/spam-can.png' onload='alert(document.cookie);'&gt;";
function addTextNode(){
    var newtext = document.createTextNode(text);
    var para = document.getElementById("p1");
    para.appendChild(newtext);
}
function innerHTMLTest(){
    var para = document.getElementById("p1");
    para.innerHTML = text;
}
function addTextNodeUnescaped(){
    var newtext = document.createTextNode(text.unescapeHTML());
    var para = document.getElementById("p1");
    para.appendChild(newtext);
}
function innerHTMLTestUnescaped(){
    var para = document.getElementById("p1");
    para.innerHTML = text.unescapeHTML();
}
</script>
</head>
<body>
<div style="border: 1px solid red">a
<p id="p1">First line of paragraph.<br /></p>b
</div><br />
<button onclick="addTextNode();">add another textNode.</button>
<button onclick="innerHTMLTest();">test innerHTML.</button>
<button onclick="addTextNodeUnescaped();">add another unescaped textNode.</button>
<button onclick="innerHTMLTestUnescaped();">test innerHTML unescaped.</button>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers