JavaScript Document queryCommandEnabled() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

document.queryCommandEnabled(command) returns a boolean: whether a named editor command is currently enabled. It is part of the legacy execCommand family and does not run the command itself.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call document.queryCommandEnabled. Start with this line.

JavaScript
document.queryCommandEnabled(command)
CallWhat it does
document.queryCommandEnabled(command)Primary signature.
document.queryCommandEnabled(...)Call with the arguments your case needs.

Built into the browser. Call queryCommandEnabled(...) on document — no import required.

Library declarations
JavaScript
document.queryCommandEnabled(command)

Parameters

ParameterDescription
commandRequired. Editor command name to probe

Return Value

Return ValueDescription
*true if enabled, else false

JavaScript Examples

Example 1 — Check SelectAll, Then Run It

MDN pattern: only call execCommand when the command is enabled.

JavaScript
const flg = document.queryCommandEnabled("SelectAll");
console.log("SelectAll enabled:", flg);

if (flg) {
  document.execCommand("SelectAll", false, null);
  console.log("SelectAll ran");
}
Try It Yourself

How It Works

  1. Ask first. queryCommandEnabled("SelectAll") returns a boolean.
  2. Log the result. Helps you see whether the command is usable now.
  3. Gate the side effect. Call execCommand only when flg is true.
  4. Remember status. This is legacy — prefer modern APIs for new products.

Example 2 — Feature-Detect Before Calling

Guard against engines that remove legacy editing APIs.

JavaScript
const hasApi = typeof document.queryCommandEnabled === "function";
console.log("queryCommandEnabled available:", hasApi);

if (hasApi) {
  console.log("bold enabled:", document.queryCommandEnabled("bold"));
} else {
  console.log("Use a modern editor / Clipboard API instead");
}
Try It Yourself

How It Works

  1. Test the method. typeof … === "function" avoids a crash if the API is gone.
  2. Probe a command. When present, check something common like "bold".
  3. Plan a fallback. If missing, point users (and code) at modern editor / clipboard APIs.
  4. Why it matters. Deprecated APIs can shrink over time — detect before you depend on them.

Example 3 — Enabled vs Supported

A command can be supported yet not enabled in the current context.

JavaScript
const names = ["bold", "SelectAll", "copy", "paste"];

names.forEach((name) => {
  const supported =
    typeof document.queryCommandSupported === "function"
      ? document.queryCommandSupported(name)
      : false;
  const enabled =
    typeof document.queryCommandEnabled === "function"
      ? document.queryCommandEnabled(name)
      : false;
  console.log(name + " → supported=" + supported + ", enabled=" + enabled);
});
Try It Yourself

How It Works

  1. List commands. Mix formatting and clipboard names for a clear contrast.
  2. Ask “supported?” Does the browser know this command at all?
  3. Ask “enabled?” Can it run now? Clipboard answers often differ.
  4. Rule of thumb. For toolbars, enable buttons from queryCommandEnabled, not only from supported.

Browser Support

Document.queryCommandEnabled() is a legacy browser DOM API. MDN marks it Deprecated and Non-standard (not part of any current specification).

✓ Deprecated · Non-standard

Document.queryCommandEnabled()

Legacy enabled-check for editor commands — still present in many engines; avoid for new apps.

Legacy Not for new apps
Google Chrome 1+
Legacy
Microsoft Edge 12+
Legacy
Mozilla Firefox 69+ (full Document)
Legacy
Apple Safari 2+
Legacy
Opera ≤12.1+
Legacy
Internet Explorer Historic support
Legacy
queryCommandEnabled() Avoid for new code

Bottom line: Widely present for legacy editing, but do not build new products on it. Prefer modern editors and the Clipboard API. See the MDN Document.queryCommandEnabled() reference.

Frequently Asked Questions

It reports whether a named editor command is currently enabled. It returns true if enabled and false if not. It does not run the command.
Yes. MDN marks it Deprecated and Non-standard. It is not part of any current specification and is no longer on track to become a standard.
Only when maintaining legacy execCommand() UIs. MDN says if you still call execCommand for a rare reason, consider checking with queryCommandEnabled() first. Prefer modern editors and the Clipboard API for new work.
queryCommandSupported() asks whether the browser supports a command at all. queryCommandEnabled() asks whether that command can run right now (focus, selection, and user-gesture rules matter).
MDN: for cut and copy, the method only returns true when called from a user-initiated thread. Outside a click or similar gesture, expect false even if the command exists.
MDN: paste returns false not only when unavailable, but also when the calling script lacks privileges to perform the action.

Next: queryCommandState()

Learn how to check whether a legacy editor command is already applied to the selection.

queryCommandState() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful