Javascript execCommand() function

The predefined function execCommand() applies to the text that is selected. You can perform actions like bold, delete, redo, undo, etc. on the selected text in the editable area. You need to use the document prefix before execCommand like this document.execCommand();.

exec Commands List


  • bold
  • copy
  • paste
  • cut
  • redo
  • undo
  • delete
  • superscript
  • subscript
  • unlink
  • selectAll
  • backColor
  • createLink
  • defaultParagraphSeparator
  • fontName
  • fontSize
  • fontColor
  • formatBlock
  • forwardDelete
  • insertHorizontalRule
  • insertHTML
  • insertImage
  • insertLineBreak
  • insertOrderedList
  • insertParagraph
  • insertText
  • insertUnorderedList
  • justifyCenter
  • justifyFull
  • justifyLeft
  • justifyRight
  • outdent
  • strikethrough
  • styleWithCss
  • useCSS

bold exec Command Example:

<!DOCTYPE html>
<html>
<head>
	<title>Javascript bold execCommand()</title>
</head>
<body>

<center>
<button onclick="makebold()">B</button>
<div style="width:50%;height:50px;" contenteditable="true" autofocus="true">Select and make me bold</div>
</center>

<script>
function makebold()
{
	document.execCommand("bold");
}
</script>
</body>
</html>

|| Other Articles ||

|| Javascript output methods ||
|| window.innerWidth Property in Javascript ||
|| className property in JS ||
|| event.preventDefault() function in JS ||
|| Math.max() function in JS ||
|| which property and button property in JS ||

Leave a Comment