Create a Summary Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Summary

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a DETAILS, a SUMMARY and a P element</button>

<script>
function myFunction() {//w  w  w . j  a  v a2 s .co m
    var x = document.createElement("DETAILS");
    document.body.appendChild(x);

    var summaryElmnt = document.createElement("SUMMARY");
    var txt1 = document.createTextNode("Copyright 2000-2014.");
    summaryElmnt.appendChild(txt1);

    var pElmnt = document.createElement("P");
    var txt2 = document.createTextNode(" - by java2s.com. All Rights Reserved.");
    pElmnt.appendChild(txt2);

    x.appendChild(summaryElmnt);
    x.appendChild(pElmnt);
}
</script>

</body>
</html>

Related Tutorials