Skip to content
Related Articles

Related Articles

HTML | DOM length Property

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 13 Aug, 2021

The DOM length property in HTML is used to get the number of items in a NodeList object. A NodeList is a collection of child Nodes. For example, the NodeList of the body will contain all the child nodes in the body i.e. paragraph, comments, headings, script, etc.


Return Value: It returns a numeric value which represents the number of nodes in the nodelist. 

Below program illustrates the DOM length property in HTML:


<!DOCTYPE html>
            DOM Length Property
            function geeksFunction() {
                var node_list = document.body.childNodes;
                var elements = "";
                var i;
                for (i = 0; i < node_list.length; i++) {
                    elements = elements + node_list[i].nodeName
                    + "    ";
                elements = elements + "<br> Length: "
                + document.body.childNodes.length;
                document.getElementById("demo").innerHTML =
    <body style = "text-align:center">
        <h2>DOM Length Property</h2>
        <button onclick="geeksFunction()">Click Here!</button>
        <p id="demo"></p>

Before Click on the button: 

After click on the button: 

Supported Browsers: The browser supported by DOM length property are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!