How to create a text node

使用: document.createTextNode();

var newDiv = document.createElement('div');
var newContent = document.createTextNode('Hello');
newDiv.appendChild(newContent);

 

note: 

1. Using this method can be used to display a user's input, to avoid XSS attacks;

2. It does not escape single or double quotes, and therefore may be injected into the code;

Guess you like

Origin www.cnblogs.com/aisowe/p/11546340.html