This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

queryCommandValue

Summary

Returns the current value of the document, range, or current selection for the given command.

Method of dom/TextRangedom/TextRange

Syntax

var object = document.queryCommandValue(/* see parameter list */);

Parameters

cmdID

Data-type
BSTR

String that specifies a command identifier.

Return Value

Returns an object of type DOM NodeDOM Node

Variant

Variant that returns the command value for the document, range, or current selection, if supported. Possible values depend on cmdID. If not supported, this method returns a Variant of type Boolean set to false.

Examples

The following example when using legacy document.selection will display an alert message of ‘false’ if the current selection is not 'bold’, or true if it is already ‘bold’

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();
        alert(rng.queryCommandValue('bold'));
// true if the rng is 'bold' already, false otherwise.
        if(rng.queryCommandSupported('bold')){
            if(rng.queryCommandEnabled('bold')){rng.execCommand('bold',false,null);}
        }
    }
}
}

Usage

 Used for changing the HTML markup of web pages.

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.

Attributions