We can create a <dt>
element via the document.createElement()
method:
var x = document.createElement("DT");
Click the button to create a DL, DT and DD element: a description list, with terms and descriptions.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from w w w. j av a 2 s .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("to style a web page"); z.appendChild(txt2); document.getElementById("myDL").appendChild(z); } </script> </body> </html>