HTML DOM Summary Object


The HTML DOM summary Object represent the <summary> element of an HTML document.

Let us now see how to create summary object −

Syntax

Following is the syntax −

document.createElement(“SUMMARY”);

Example

Let us see an example of HTML DOM summary object −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      text-align: center;
      background-color: #fff;
      color: #0197F6;
   }
   h1 {
      color: #23CE6B;
   }
   .btn {
      background-color: #fff;
      border: 1.5px dashed #0197F6;
      height: 2rem;
      border-radius: 2px;
      width: 60%;
      margin: 2rem auto;
      display: block;
      color: #0197F6;
      outline: none;
      cursor: pointer;
   }
</style>
</head>
<body>
<h1>DOM summary Object Demo</h1>
<button onclick="createSummary()" class="btn">Create a summary object</button>
<script>
   function createSummary() {
      var details = document.createElement("DETAILS");
      var summary = document.createElement("SUMMARY");
      var para = document.createElement("P");
      var paraTxt = document.createTextNode("- I'm para element");
      para.appendChild(paraTxt);
      var summaryTxt = document.createTextNode("I'm summary element");
      summary.appendChild(summaryTxt);
      details.appendChild(summary);
      details.appendChild(para);
      document.body.appendChild(details);
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Create a summary object” button to create a summary object.

Click to display −

Updated on: 30-Jul-2019

34 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements