You are here: Reference > JavaScript > client-side > selection and ranges > methods > queryCommandText (document, TextRange, ...)

queryCommandText method (document, TextRange, ...)

Browser support:
Returns the description of the specified command.
The description of some commands depend on the current state of their target. To get the state of a command, use the queryCommandState method. See the example for details.
Note: the queryCommandSupported method is supported by Firefox, but it is not implemented and raises an exception.

Syntax:

object.queryCommandText (commandIdentifier);
You can find the related objects in the Supported by objects section below.

Parameters:

commandIdentifier
Required. A case-insensitive string that specifies the name of the command. See command identifiers for more information.

Return value:

String. Information about the specified command.

Example HTML code 1:

This example illustrates the use of the queryCommandText method:
<head>
    <script type="text/javascript">
        function GetCommandDescription () {
                // try..catch is necessary because the queryCommandText method is supported but not implemented in Firefox.
            try {
                alert (document.queryCommandText ('Undo'));
                alert (document.queryCommandText ('Redo'));
            }
            catch (e) {
                alert ("Your browser does not support the queryCommandText method!");
            }
        }
    </script>
</head>
<body>
    <div contenteditable="true">Edit this text to modify the description of the 'undo' and 'redo' commands!</div>
    <br /><br />
    <button onclick="GetCommandDescription ();">Get the description of the 'undo' and 'redo' commands!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content