HTML DOM dl Object
The DOM dl object is used to represent the HTML <dl> element. The dl element can be accessed using the getElementById() method. The dl is used to create a description list in HTML.
Syntax:
document.getElementById("id");
Where ‘id’ is the ID assigned to the dl tag.
Example 1: In the below program the dl element is accessed and the color of the text inside the description list is changed.
HTML
<!DOCTYPE html> < html > < body > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >DOM dl Object</ h2 > < dl id = "id" > < dt >Sorting</ dt > < dd >Merge sort</ dd > </ dl > < button onclick = "Beginner()" >Click Here!</ button > < p id = "p" style = "color:green" ></ p > < script > function Beginner() { let doc = document.getElementById("id").innerHTML; document.getElementById("p").innerHTML = doc; } </ script > </ body > </ html > |
Output:
Example 2: DL Object can be created by using the document.createElement method.
HTML
<!DOCTYPE html> < html > < body > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >DOM dl Object</ h2 > < button onclick = "Beginner()" >Click Here!</ button >< br > < script > function Beginner() { // Creating a dl element let doc = document.createElement("DL"); doc.setAttribute("id", "dl"); document.body.appendChild(doc); // Creating a DT element let doc1 = document.createElement("DT"); let txt1 = document.createTextNode("Sorting"); doc1.appendChild(txt1); doc1.setAttribute("id", "dt"); document.getElementById("dl").appendChild(doc1); // Creating a dd element let doc2 = document.createElement("DD"); let txt2 = document.createTextNode("Merge sort"); doc2.appendChild(txt2); document.getElementById("dl").appendChild(doc2); } </ script > </ body > </ html > |
Output:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Safari
- Opera
Contact Us