In this section, we will learn what the Element nodeValue property is and how to use it in JavaScript.
What is Element nodeValue Property in JavaScript?
The JavaScript Element nodeValue property is used to get and set the value of an element (AKA node) in an HTML document.
JavaScript nodeValue Property Syntax:
element.nodeValue; element.nodeValue = newValue;
JavaScript nodeValue Property Input Value
The value we set for this property will be used as the new value of the target node in an HTML document.
JavaScript nodeValue Property Return Value
The return value of this property is of type string and might be:
– A `null` value for Element-node and Document-node.
– The value of the attribute, if the target node is an Attribute-node.
– If the target node is Text-node, then its content will return.
– If the target node is Comment node, its content will return.
Example: using nodeValue Property in JavaScript
See the Pen using nodeValue Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.