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:
<!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> |
Output:
Before Clicking On button:

After Clicking On Button:
Example-2 : Ol Object can be created by using the document.createElement method.
<!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> |
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
Recommended Posts:
- HTML | DOM Object Object
- HTML | DOM li Object
- HTML | DOM S Object
- HTML | DOM Bdo Object
- HTML | DOM Kbd Object
- HTML | DOM Del Object
- HTML | DOM Pre Object
- HTML | DOM Map Object
- HTML | DOM Nav Object
- HTML | DOM Ul Object
- HTML | DOM BR Object
- HTML DOM Aside Object
- HTML | Object tag
- HTML | DOM Div Object
- HTML | DOM DD Object
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.



