Javascript Reference - HTML DOM DT Object








The DT object represents an HTML <dt> element.

Standard Properties and Events

The DT object supports the standard properties and events.

Example

The following code shows how to get a <dt> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<dl>
  <dt id="myDT">html</dt>
  <dd>mark up</dd>
</dl><!--from w  w w .  j  ava  2  s  . c  o  m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myDT").innerHTML;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <dt> element by using the document.createElement() method


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from   ww w  . j a  v  a2 s.co m-->
    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: