Open In App

HTML DOM Dialog showModal() Method

Last Updated : 22 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

dialogObject.showModal()

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

HTML




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


Output: 

 

Supported Browsers:

  • Google Chrome 37.0
  • Opera 24.0
  • Safari 6.0

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads