English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
Return node value:
node.nodeValue
Set node value:
node.nodeValue = newValue
var x = document.getElementById("myPara").firstChild.nodeValue;Testen Sie heraus‹/›
All browsers fully support the nodeValue attribute:
Attribute | |||||
nodeValue | Is | Is | Is | Is | Is |
Value | Description |
---|---|
newValue | Specify the node value of the specified node |
Return value: | A string representing the node's value. Possible values:
|
---|---|
DOM version: | DOM level1 |
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‹/›
HTML DOM-Referenz:node .nodeName-Eigenschaft
HTML DOM-Referenz:node .nodeType-Eigenschaft
HTML DOM-Referenz:node .childNodes-Eigenschaft