Open In App

HTML DOM Dialog open Property

The DOM Dialog open Property is used to set or return whether the dialog box should be open or not. It is new in HTML5 If open, it means the user can interact with it. 

Syntax:



dialogObject.open
dialogObject.open = true|false

Property Values: It accepts two values i.e. true|false which specifies whether a dialog window should be open or not. By default, it is false.

Example 1: This example returns the value of Dialog open property. 






<!DOCTYPE html>
<html>
 
<body>
    <h3> HTML DOM Dialog open Property</h3>
    <dialog id="Dialog" style="color:green">
        Welcome to GeeksforGeeks
      </dialog>
    <button onclick="openDialog()">
        Get the value of open property
      </button>
    <p id="geeks"> </p>
 
    <script>
        function openDialog() {
            let gfg =
                document.getElementById("Dialog").open;
            document.getElementById("geeks").innerHTML = gfg;
        }
    </script>
</body>
</html>

Output: 

 

Example 2: This example sets the value of Dialog open property. 




<!DOCTYPE html>
<html>
 
<body>
    <h3> HTML DOM Dialog open Property</h3>
    <dialog id="Dialog" style="color:green">
        Welcome to GeeksforGeeks
      </dialog>
    <button onclick="openDialog()">
        Set the value of open property
      </button>
    <p id="geeks"> </p>
 
    <script>
        function openDialog() {
            let gfg =
             document.getElementById("Dialog").open = true;
            document.getElementById("geeks").innerHTML = gfg;
        }
    </script>
</body>
</html>

Output: 

 

Supported Browsers:


Article Tags :