HTML DOM Element nodeValue Eigenschaft
- Previous Page nodeType
- Next Page normalize()
- Go Up One Level HTML DOM Elements-Objekt
Definition and Usage
nodeValue
The property sets or returns the value of the node.
If the node is an element node, then nodeValue
The property will return null
.
Note:If you want to return the text of the element, remember that the text is always located within a Text node, and you must return the node value of the Text node:
element.childNodes[0].nodeValue
For other node types:nodeValue
The property will return different values for different node types.
Alternative:
See also:
Example
Example 1
Return the node value of the first <button> element in the document:
document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
Example 2
Get the node name, value, and type of the first child of "myDIV":
const x = document.getElementById("myDIV").firstChild; let text = ""; text += "Name: " + x.nodeName + "<br>"; text += "Value: " + x.nodeValue + "<br>"; text += "Type: " + x.nodeType;
Syntax
Return node value:
node.nodeValue
Set node value:
node.nodeValue = value
Attribute Value
Value | Description |
---|---|
value | Node value. |
Return Value
Type | Description |
---|---|
String |
Node value.
|
Browser Support
element.nodeValue
It is a DOM Level 1 (1998) feature.
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page nodeType
- Next Page normalize()
- Go Up One Level HTML DOM Elements-Objekt