Skip to content
Related Articles

Related Articles

HTML | DOM Details open Property

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 27 Jan, 2022

The Details open property in HTML DOM is used to set or return whether the hidden information is visible or not to the user. This property is used to reflect the HTML open attribute. 
Syntax: 
 

  • It returns the Details open property. 
     
detailsObject.open
  • It is used to set the Details open property. 
     
detailsObject.open = true|false

Property Values: It accepts two property values which are listed below: 
 

  • true: It specifies the hidden information should be visible.
  • false: It specifies that the hidden information should not be visible. It is false by default. 

Return Value: It returns a boolean value which represents that the hidden information would be visible or not.
Example 1: This example returns the Details open Property. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM details open Property
    </title>
     
    <style>
        h2 {
            color: green;
            font-size: 35px;
        }
        summary {
            font-size: 40px;
            color: #090;
            font-weight: bold;
        }
    </style>
</head>
 
<body>
    <center>
        <h2>DOM Details open Property </h2>
 
        <!-- assigning id to details tag. -->
        <details id="GFG">
            <summary>GeeksforGeeks</summary>
            <p>A computer science portal for geeks</p>
            <div>
                It is a computer science portal
                where you can learn programming.
            </div>
        </details>
 
        <br>
        <button onclick="myGeeks()">Submit</button>
         
        <script>
            function myGeeks() {
                 
                // Accessing details tag.
                var x = document.getElementById("GFG");
                 
                // Display hidden information
                // using open property.
                x.open = true;
            }
        </script>
    </center>
</body>
 
</html>                   

Output: 
Before Clicking on Button: 
 

After Clicking on Button: 
 

Example 2: This example sets the Details open Property. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>DOM details open Property</title>
    <style>
        h2 {
            color: green;
            font-size: 35px;
        }
         
        summary {
            font-size: 40px;
            color: #090;
            font-weight: bold;
        }
    </style>
</head>
 
<body>
    <center>
        <h2>DOM Details open Property </h2>
 
        <!-- assigning id to details tag. -->
        <details id="GFG">
            <summary>GeeksforGeeks</summary>
            <p>A computer science portal for geeks</p>
            <div>It is a computer science portal
                where you can learn programming.</div>
        </details>
 
        <br>
        <button onclick="myGeeks()">Submit</button>
         
        <p id="sudo" style="font-size:25px;"></p>
        <script>
            function myGeeks() {
                // Accessing details tag.
                var x = document.getElementById("GFG");
                 
                // Display hidden information
                // using open property.
            var g = x.open = false;
                document.getElementById("sudo").innerHTML = g;
            }
        </script>
    </center>
</body>
 
</html>            

Output : 
Before Clicking on Button: 
 

After Clicking on Button: 
 

Supported Browsers: The browser supported by DOM Details open property are listed below: 
 

  • Google Chrome 12.0
  • Firefox 49.0
  • Opera 15.0
  • Safari 6.0
  • Edge 79 and above

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!