Example 1 — Check SelectAll, Then Run It
MDN pattern: only call execCommand when the command is enabled.
const flg = document.queryCommandEnabled("SelectAll");
console.log("SelectAll enabled:", flg);
if (flg) {
document.execCommand("SelectAll", false, null);
console.log("SelectAll ran");
} How It Works
- Ask first.
queryCommandEnabled("SelectAll")returns a boolean. - Log the result. Helps you see whether the command is usable now.
- Gate the side effect. Call
execCommandonly whenflgistrue. - Remember status. This is legacy — prefer modern APIs for new products.

