You are here: Reference > JavaScript > client-side > selection and ranges > methods > queryCommandEnabled (document, TextRange, ...)

queryCommandEnabled method (document, TextRange, ...)

Browser support:
Returns whether the execution of the specified command can be successful, using the execCommand method.
The return value of the queryCommandEnabled method sometimes depends on the state of the current selection in Internet Explorer. For example, if no content is selected within the document, the queryCommandEnabled method of the document object returns false for the 'bold' command, but if some text is selected it returns true.
  • The use of a non-enabled command for the execCommand method does not raise an exception.
  • The use of a non-supported command for the queryCommandEnabled method raises an exception in Internet Explorer.
Use the queryCommandSupported method to detect whether a command is supported.


object.queryCommandEnabled (commandIdentifier);
You can find the related objects in the Supported by objects section below.


Required. A case-insensitive string that specifies the name of the command. See command identifiers for more information.

Return value:

Boolean. One of the following values:
false The specified command is enabled.
true The specified command is disabled.

Example HTML code 1:

This example illustrates the use of the queryCommandEnabled method:
    <script type="text/javascript">
        function SetToBold () {
            if (document.queryCommandEnabled ("bold")) {
                document.execCommand ('bold', false, null);
            else {
                alert ("Please select some content!");
    <div contenteditable="true">Select a part of this text!</div>
    <br /><br />
    <button onclick="SetToBold ();">Toggle the bold state of the selected text</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content