Tuesday, July 28, 2026
HomeLanguagesJavascriptHTML DOM queryCommandEnabled() Method

HTML DOM queryCommandEnabled() Method

The queryCommandEnabled() method is used to check whether the specified command is enabled by the browser or not.

Syntax:

isEnabled = document.queryCommandEnabled( command );

Parameters:

  • command: It is the command for which support has to be determined.

Return value: It returns a Boolean value that specifies if the command is enabled by the browser. It returns true if the command is enabled and false if the command is disabled.

Example 1: This example shows if the “selectAll” command is enabled or not. We can use this information to execute the command using the execCommand() method or show a message to the user if it is not supported.

HTML




<html>
<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM queryCommandEnabled() method
    </title>
</head>
  
<body>
    <h1>neveropen</h1>
  
    <p>
        A<br>
        B<br>
    </p>
  
    <button onclick="checkCommand()">
        Click
    </button>
  
    <script>
        function checkCommand() {
  
            // Check if the command is
            // enabled using the 
            // queryCommandEnabled() method
            var isEnabled = document
                .queryCommandEnabled("SelectAll");
  
            // Show the output to the console
            console.log(isEnabled);
  
            // Execute the command if the 
            // task is enabled
            if (isEnabled) {
                document.execCommand("SelectAll",
                    false, null);
            }
        }
    </script>
</body>
  
</html>


Output:

Before Clicking the Button:

After Clicking the Button:

Example 2: This example shows the case when this method will return false as the given command is not a valid one.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM queryCommandEnabled() method
    </title>
</head>
  
<body>
    <h1>neveropen</h1>
  
    <p>
        A<br>
        B<br>
    </p>
  
    <button onclick="checkCommand()">
        Click
    </button>
  
    <script>
        function checkCommand() {
  
            // Checking to see if an invalid
            // command is enabled
            var isEnabled =
                document.queryCommandEnabled("Select");
  
            // Show the output to the console
            console.log(isEnabled);
        }
    </script>
</body>
  
</html>


  • Output:

    Before Clicking the Button:
     

  • After Clicking the Button:

Supported Browsers::

  • Google Chrome
  • Edge 12
  • Firefox 41
  • Safari
  • Opera
  • Internet Explorer
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

5 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS