HTML DOM li Object
Last Updated :
14 Jun, 2023
The DOM Li Object is used to represent the HTML <li> element. The li element is accessed by getElementById().
Properties:
- value: It has an attribute named value which is used to return the value of the value attribute of the <li> tag.
Syntax:
document.getElementById("ID");
Where “id” is the ID assigned to the “li” tag.
Example 1: In this example, we will see the use of DOM Li Object.
html
<!DOCTYPE html>
< html >
< head >
< title >DOM li Object</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >DOM Li Object </ h2 >
< ol >
< 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.
let g = document.getElementById("GFG");
g.value = "100";
}
</ script >
</ body >
</ html >
|
Output:
Example 2: <li> Object can be created by using the document.createElement method.
HTML
<!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.
let G = document.createElement("LI");
let F = document.createTextNode("Placement");
G.appendChild(F);
document.getElementById("GFG").appendChild(G);
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers: The browser supported by DOM Li Object are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...