Create a DT Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:DT

Introduction

You can create a <dt> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a DL, DT and DD element: a description list, with terms and descriptions</button>

<script>
function myFunction() {/*from w  ww  .jav  a 2s .  c om*/
    var x = document.createElement("DL");
    x.setAttribute("id", "myDL");
    document.body.appendChild(x);

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

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

</body>
</html>

Related Tutorials