Javascript DOM HTML Summary Object create

Introduction

We can create a <summary> element via the document.createElement() method:

var x = document.createElement("SUMMARY");

Click the button to create a DETAILS, a SUMMARY and a P element.

View in separate window

<!DOCTYPE html>
<html>
<body>


<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/*  ww w .  ja  va  2 s .  c o  m*/
  var x = document.createElement("DETAILS");
  document.body.appendChild(x);

  var summaryElmnt = document.createElement("SUMMARY");
  var txt1 = document.createTextNode("Copyright 2020-2024.");
  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>



PreviousNext

Related