--- title: Document.createTextNode() slug: Web/API/Document/createTextNode translation_of: Web/API/Document/createTextNode ---
{{APIRef("DOM")}}

Создаёт новый текстовый узел.

Синтаксис

var text = document.createTextNode(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
{{SpecName("DOM3 Core", "core.html#ID-1975348127", "Document.createTextNode()")}} {{Spec2("DOM3 Core")}} No change
{{SpecName("DOM2 Core", "core.html#ID-1975348127", "Document.createTextNode()")}} {{Spec2("DOM2 Core")}} Initial definition

Совместимость

{{Compat("api.Document.createTextNode")}}