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)

Parameters:
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;
    x.nodeType;
    x.nodeName;
    x.nodeValue;
    

    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”.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
      
    <body>
      
        <head>
      
            <script>
                <!--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;
                    document.getElementById("GeeksForGeeks"
                                    ).innerHTML = res;
                }
            </script>
        </head>
        <!--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!
        </button>
      
        <!-- below paragraph Tag is used to print
        the value of nodeValue properties-->
        <p id="GeeksForGeeks"></p>
      
    </body>
      
    </html>                    

    chevron_right

    
    

    Output:
    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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.