Open In App
Related Articles

HTML | DOM Details open Property

Improve Article
Improve
Save Article
Save
Like Article
Like

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() {
                 
                // Return the details open Property
                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() {
                // set details open property
                var x = document.getElementById("GFG");
                 
                // Hide 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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 Aug, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials