--- title: Document.queryCommandState() slug: Web/API/Document/queryCommandState tags: - API - DOM - Reference translation_of: Web/API/Document/queryCommandState ---
queryCommandState() メソッドは、現在の選択範囲に特定の {{domxref("Document.execCommand()")}} コマンドが適用されているかどうかを知らせます。
queryCommandState(String command)
command は {{domxref("Document.execCommand()")}} のコマンドです。
queryCommandState() は {{jsxref("Boolean")}} 値、または状態が不明な場合は null を返す可能性があります。
<div contenteditable="true">Select a part of this text!</div> <button onclick="makeBold();">Test the state of the 'bold' command</button>
function makeBold() {
var state = document.queryCommandState("bold");
switch (state) {
case true:
alert("The bold formatting will be removed from the selected text.");
break;
case false:
alert("The selected text will be displayed in bold.");
break;
case null:
alert("The state of the 'bold' command is indeterminable.");
break;
}
document.execCommand('bold');
}
{{EmbedLiveSample('Example')}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| execCommand |
{{Compat("api.Document.queryCommandState")}}
queryCommandState() に関するブラウザーのバグ: Scribe's "Browser Inconsistencies" documentation