Create a DList Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:DList

Introduction

You can create a <dl> 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  www  .j a  va2 s  .c o  m
    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