execCommand and contenteditable

suggest change

document.execCommand is deprecated. Browsers still implement much of it for contenteditable, but clipboard commands can fail without a user gesture, and paste is often blocked. insertHTML parses HTML and can run markup you did not intend to trust.

Syntax

Parameters

commandId value
⋮ Inline formatting commands
backColor Color value String
bold
createLink URL String
fontName Font family name
fontSize “1”, “2”, “3”, “4”, “5”, “6”, “7”
foreColor Color value String
strikeThrough
superscript
unlink
⋮ Block formatting commands
delete
formatBlock “address”, “dd”, “div”, “dt”, “h1”, “h2”, “h3”, “h4”, “h5”, “h6”, “p”, “pre”
forwardDelete
insertHorizontalRule
insertHTML HTML String
insertImage URL String
insertLineBreak
insertOrderedList
insertParagraph
insertText Text string
insertUnorderedList
justifyCenter
justifyFull
justifyLeft
justifyRight
outdent
⋮ Clipboard commands
copy Currently Selected String
cut Currently Selected String
paste
⋮ Miscellaneous commands
defaultParagraphSeparator
redo
selectAll
styleWithCSS
undo
useCSS

Listening to changes of contenteditable

Getting started

Formatting

Copy to clipboard from a textarea using execCommand("copy")

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents