Создает новый текстовый узел.
Синтаксис
var text = document.createTextNode(data);
text
- это текстовый узел.data
- это строка с данными, которые будут помещены в текстовый узел.
Пример
<!DOCTYPE html>
<html lang="en">
<head>
<title>createTextNode example</title>
<script>
function addTextNode(text) {
var newtext = document.createTextNode(text),
p1 = document.getElementById("p1");
p1.appendChild(newtext);
}
</script>
</head>
<body>
<button onclick="addTextNode('YES! ');">YES!</button>
<button onclick="addTextNode('NO! ');">NO!</button>
<button onclick="addTextNode('WE CAN! ');">WE CAN!</button>
<hr />
<p id="p1">First line of paragraph.</p>
</body>
</html>
Спецификации
Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Core Specification Определение 'Document.createTextNode()' в этой спецификации. |
Устаревшая | No change |
Document Object Model (DOM) Level 2 Core Specification Определение 'Document.createTextNode()' в этой спецификации. |
Устаревшая | Initial definition |
Совместимость
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | (Да) | (Да) | (Да) | (Да) | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? |