HTML DOM Document execCommand() method

Definition and usage

execCommand() The method is deprecated. Do not use it.

The applet attribute returns empty in all new browsers HTMLCollection.

HTML5 does not support the <applet> element.

Alternative:

Document designMode attribute

Element contentEditable attribute

Example

Make the selected text bold:

document.execCommand("bold");

Try it yourself

Syntax

document.execCommand(command, showUI, value)

Parameters

Parameters Description
command

Name of the command to be executed:

  • "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"
  • "subscript"
  • "superscript"
  • "undo"
  • "unlink"
  • "useCSS"
showUI Boolean. Specify whether the UI should be displayed.
value Some commands require a value to be completed.

Return value

Type Description
Boolean value Idan dake ga amfani, wani aza true, amma wani aza false.