Open In App

HTML DOM Dialog close() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The DOM Dialog close() method is used to close the dialog. The Dialog element is accessed by getElementById(). It is used in HTML5. While using this method, the user can interact with other elements on the page. It is used with the Dialog show() method. 

Syntax:

dialogObject.close()

Example: This example shows the working of Dialog close() Method: 

HTML




<!DOCTYPE html>
<html>
 
<body>
 
    <h3> HTML DOM Dialog close() Method</h3>
    <p>
          Click on the below buttons to
        show or close the dialog window.
      </p>
    <button onclick="showDialog()">
          Show dialog box
      </button>
    <button onclick="closeDialog()">
          Close dialog box
      </button>
    <dialog id="showDialog" style="color:green">
        Welcome to GeeksforGeeks
      </dialog>
 
    <script>
        let gfg =
            document.getElementById("showDialog");
        function showDialog() {
            gfg.show();
        }
        function closeDialog() {
            gfg.close();
        }
    </script>
</body>
   
</html>


Output: 

 

Supported Browsers:

  • Google Chrome 37.0
  • Opera 24.0
  • Safari 6.0

Last Updated : 22 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads