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:

  • It returns the open property:
    dialogObject.open
  • It sets the open property:
    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.

  • true:It states that the dialog window is open.
  • false: It states that the dialog window is not open.
  • Example-1: This example returns the value of Dialog open property.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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() { 
    var gfg = document.getElementById("Dialog").open; 
    document.getElementById("geeks").innerHTML = gfg;
    </script>
      
    </body>
    </html>                    
                        

    chevron_right

    
    

    Output:
    Before Clicking on Button:

    After Clicking on Button:

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

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!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() { 
    var gfg = document.getElementById("Dialog").open = true; 
    document.getElementById("geeks").innerHTML = gfg;
    </script>
      
    </body>
    </html>                    
                        

    chevron_right

    
    

    Output:
    Before Clicking on Button:

    After Clicking on Button:

    Supported Browsers:

    • Google Chrome
    • Opera
    • Safari


    My Personal Notes arrow_drop_up

    Check out this Author's contributed articles.

    If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




    Article Tags :
    Practice Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.