Returns a Boolean value that indicates the current state of the command.
Method of dom/TextRangedom/TextRange
Syntaxvar result = document.queryCommandState(/* see parameter list */);Parameters cmdID
String that specifies a command identifier.
Returns an object of type BooleanBoolean
Boolean
Boolean that returns one of the following possible values:
Return value Description true The given command has been executed on the object. false The given command has not been executed on the object. ExamplesThis example feature tests for window.getSelection and if not available (legacy IE versions) falls back to document.selection to create a range object. Then queryCommandState is used to determine if the range object can execute the 'bold' command.
function makeBold(el){ if(window.getSelection){ var sel=document.getSelection(); var range = sel.getRangeAt(0), content = range.extractContents(), span = document.createElement('b'); span.appendChild(content); var htmlContent = span.innerHTML; range.insertNode(span); }else{ var sel=document.selection; if(sel){ var rng=sel.createRange(); if(rng.queryCommandEnabled('bold')){rng.execCommand('bold',false,null);} } } }Usage
Used to add HTML markup to web documents.Notes Remarks
This method is a wrapper function for the command constants. You can obtain an IHTMLDocument2 interface using IID_IHTMLDocument2 for the IID. This method is a wrapper function for the command constants. You can obtain an IHTMLControlRange interface using IID_IHTMLControlRange for the IID. This method is a wrapper function for the command constants. You can obtain an IHTMLTxtRange interface using IID_IHTMLTxtRange for the IID.
AttributionsMicrosoft Developer Network: [queryCommandState Method Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4