HTML | DOM li Object
The DOM Li Object is used to represent the HTML <li> element. The li element is accessed by getElementById().
Properties:
- value: It has a attribute named value which is used to return the value of value attribute of the <li> tag
Syntax:
document.getElementById("ID");
Where “id” is the ID assigned to the “li” tag.
Example-1:
<!DOCTYPE html> <html> <head> <title>DOM li Object</title> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM Li Object </h2> <ol> <!-- Assigning id to 'li tag' --> <li id="GFG">Geeks</li> <li>Sudo</li> <li>Gfg</li> <li>Gate</li> <li>Placement</li> </ol> <button onclick="myGeeks()">Submit</button> <script> function myGeeks() { // Accessing 'li' tag. var g = document.getElementById("GFG"); g.value = "100"; } </script> </body> </html> |
Output:
Before Clicking On Button:

After Clicking On Button:

Example-2: <li> Object can be created by using the document.createElement method.
<!DOCTYPE html> <html> <head> <title>DOM li Object</title> </head> <body> <h1>GeeksforGeeks</h1> <h2>DOM Li Object </h2> <ol ID="GFG"> <li>Geeks</li> <li>Sudo</li> <li>Gfg</li> <li>Gate</li> </ol> <button onclick="myGeeks()">Submit</button> <script> function myGeeks() { // li tag created. var G = document.createElement("LI"); var F = document.createTextNode("Placement"); G.appendChild(F); document.getElementById("GFG").appendChild(G); } </script> </body> </html> |
Output:
Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by DOM Li Object are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM Object Object
- HTML | DOM Kbd Object
- HTML DOM Aside Object
- HTML | DOM Bdo Object
- HTML | DOM Pre Object
- HTML | DOM DD Object
- HTML | DOM Ol Object
- HTML | DOM Del Object
- HTML | DOM Nav Object
- HTML | DOM DFN Object
- HTML | DOM Ul Object
- HTML| DOM HR Object
- HTML | DOM Map Object
- HTML | DOM DT Object
- HTML | DOM dl 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.



