HTML | DOM Ol Object

The DOM Ol Object is used to represent the HTML <ol> element . The ol element is accessed by getElementById(). To read more about lists check HTML | Lists.

Properties:

  • compact: It is used to set or return whether the size of the list would be displayed normal or not.
  • reversed: It is used to set or return whether the list item is displayed in descending order or ascending order.
  • start: It is used to set or return the value of the start attribute in an <ol> element.
  • type: It is used to set or return the value of the type attribute in an <ol> element.

Syntax:



document.getElementById("ID");

Where “id” is the ID assigned to the “ol” tag.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1
        GEEKSFORGEEKS 
    </h1>
    <h2
         DOM Ol Object
    </h2>
    <p>
        Ordered Lists
    </p>
    <!--  Assigning id to 'ol' tag.  -->
    <ol id="GFG">
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ol>
    
    <button onclick="Geeks()">Submit</button>
    
    <script>
        function Geeks() {
            
            //  Accessing ol tag 
            //  and  starts with 101.
            var g = document.getElementById("GFG");
            g.start = "100";
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On button:

After Clicking On Button:

Example-2 : Ol Object can be created by using the document.createElement method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1
        GEEKSFORGEEKS 
    </h1>
    <h2
         DOM Ol Object
    </h2>
    <button onclick="Geeks()">Submit</button>
    <script>
        function Geeks() {
             
            //  Creating 'ol' object
            var g = document.createElement("OL");
            g.setAttribute("id", "GFG");
            document.body.appendChild(g);
  
            var x = document.createElement("LI");
            var y = document.createTextNode("geeks");
            x.appendChild(y);
            document.getElementById("GFG").appendChild(x);
  
            var w = document.createElement("LI");
            var f = document.createTextNode("sudo");
            w.appendChild(f);
            document.getElementById("GFG").appendChild(w);
        }
    </script>
</body>
  
</html>

chevron_right


Output :

Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by DOM Ol Object are listed below:

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


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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.