English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM nodeValue attribute

HTML DOM Element-Objekt

nodeValueProperty returns or sets the value of the current node.

For text, comment, and CDATA nodes, nodeValue returns the content of the node.

For attribute nodes, it will return the value of the attribute.

nodeValue attribute can be used as an alternative methodtextContentProperty.

Syntax:

Return node value:

node.nodeValue

Set node value:

node.nodeValue = newValue
var x = document.getElementById("myPara").firstChild.nodeValue;
Testen Sie heraus‹/›

Browser compatibility

All browsers fully support the nodeValue attribute:

Attribute
nodeValueIsIsIsIsIs

Attribute value

ValueDescription
newValueSpecify the node value of the specified node

Technical details

Return value:A string representing the node's value.
Possible values:
  • Return for element node and document nodenull

  • Return the attribute node's attribute value

  • Return the content of the text node

  • Return the content of the comment node

DOM version:DOM level1

More examples

Set the node value of an element in the document:

document.getElementById("myPara").firstChild.nodeValue = "HELLO WORLD";
Testen Sie heraus‹/›

Geben Sie den Node-Namen, den Node-Typ und den Node-Wert des ersten Kindknotens des div zurück:

<div id="div-1">Dies ist ein div-Element.</div>
<script>
var x = document.getElementById("div-1).firstChild;
var txt = "";
txt += "Der Node-Name: " + x.nodeName + "<br>";
txt += "Der Node-Wert: " + x.nodeValue + "<br>";
txt += "Der Node-Typ: " + x.nodeType;
document.getElementById("para").innerHTML = txt;
</script>
Testen Sie heraus‹/›

Verwandte Referenzen

HTML DOM-Referenz:node .nodeName-Eigenschaft

HTML DOM-Referenz:node .nodeType-Eigenschaft

HTML DOM-Referenz:node .childNodes-Eigenschaft

HTML DOM Element-Objekt