English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
execCommand()The method is to execute a command on the current document, current selection, or specified range.
When the HTML document has switched todesignModeits document object will use the execCommand method to run the command for the current editable area.
Most commands affect the document selection (bold, italic, etc.), while other commands insert new elements (add links) or affect the entire line (indent).
UseWhen contentEditable is, the execCommand() affects the currently active editable element.
document.execCommand(commandName, showDefaultUI, valueArgument)
document.execCommand("bold");Test and see‹/›
The numbers in the table specify the first browser version that fully supports the execCommand() method:
Method | |||||
execCommand() | Is | 41 | 29 | 10 | 9 |
Parameter | Description |
---|---|
commandName | A string that specifies the name of the command to be executed. Here is a list of possible commands: "backColor" "bold" "createLink" "copy" "cut" "defaultParagraphSeparator" "delete" "fontName" "fontSize" "foreColor" "formatBlock" "forwardDelete" "insertHorizontalRule" "insertHTML" "insertImage" "insertLineBreak" "insertOrderedList" "insertParagraph" "insertText" "insertUnorderedList" "justifyCenter" "justifyFull" "justifyLeft" "justifyRight" "outdent" "paste" "redo" "selectAll" "strikethrough" "styleWithCss" "superscript" "undo" "unlink" "useCSS" |
showDefaultUI | A boolean value indicating whether the default user interface should be displayed |
valueArgument | For commands that require input parameters, it is the string that provides this information. For example, insertImage requires the URL of the image to be inserted. |
Return Value: | A boolean value, false if the command is not supported or disabled |
---|
Change the fontSize of the selected text:
document.execCommand("fontSize", false, 7);Test and see‹/›
DOM Document:designModeProperties
DOM Element:contentEditableProperties