Javascript Reference - HTML DOM DList Object








The DList object represents an HTML <dl> element.

Standard Properties and Events

The DList object supports the standard properties and events.

Example

We can access a <dl> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<dl id="myDL">
  <dt>html</dt>
  <dd>mark up</dd>
  <dt>css</dt>
  <dd>style</dd>
</dl><!-- www  . jav a2 s  .com-->
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myDL").innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <dl> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from  w  ww . j a  va  2  s  .  com-->
    var x = document.createElement("DL");
    x.setAttribute("id", "myDL");
    document.body.appendChild(x);

    var y = document.createElement("DT");
    var txt1 = document.createTextNode("html");
    y.appendChild(txt1);
    y.setAttribute("id", "myDT");
    document.getElementById("myDL").appendChild(y);

    var z = document.createElement("DD");
    var txt2 = document.createTextNode("mark up");
    z.appendChild(txt2);
    document.getElementById("myDL").appendChild(z);
}
</script>

</body>
</html>

The code above is rendered as follows: