HTML | DOM nodeValue Property

The HTML DOM nodeValue Property is used to describe the property of a given node. Its used to set or get the nodeValue in Any Html document. Prerequist DOM (Document Object Model)

No parameters required.

Return value: The HTML nodeValue property return the following type of values

  • null: for element and document nodes.
  • attribute value: for any attribute.
  • content: for any text node or comment nodes.
  • Syntax

    var x = document.getElementById("nodeId").firstChild;

    Example: Following example create a paragraph tag which is “divId”
    And provide a button which produces paragraph tag properties and return its value to a tag whose id is “GeeksForGeeks”.





    <!DOCTYPE html>
                <!--utility function to demonstarte nodValue Property-->
                function exampleFunction() {
                    <!--var x used to get the information of those node -->
                    // for which you want to perform nodeVlaue properties
                    var x = document.getElementById("divId").firstChild;
                    // res is used to store the properties 
                    var res = "";
                    // we append res tag and return it to a tag  
                    / /whose id is GeeksforGeeks.
                    res += "The node name: " + x.nodeName + "<br>";
                    res += "The node value: " + x.nodeValue + "<br>";
                    res += "The node type: " + x.nodeType;
                                    ).innerHTML = res;
        <!--In this example we will create a node of the type div
        and a button which calls a function name "exampleFunction", 
        on clicking of this button it will show the 
            properties of div node -->
        <p id="divId">paragraph tag</p>
            <p>click to know the nodeValue properties 
            of the paragraph tag</p>
        <button onclick="exampleFunction()">
            Click Me!
        <!-- below paragraph Tag is used to print
        the value of nodeValue properties-->
        <p id="GeeksForGeeks"></p>



    Before clicking the button:

    After clicking the button:

    Supported Browsers: The browser supported by DOM nodeValue properties are listed below:

  • Google Chrome
  • Apple Safari
  • Firefox
  • Opera
  • Edge

  • My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.