HTML | DOM execCommand() Method
The DOM execCommand() method in HTML DOM is used to execute a command specified by the user on the editable selected section.
Syntax:
document.execCommand( command, showUI, value )
Parameters: This method accepts three parameters which are listed below:
- command: This parameter hold the name of command which is execute on the selected section. There are many commands in HTML some of them are: backcolor, bold, copy, cut, delete etc.
- showUI: It holds the Boolean value which indicating whether the UI shown or not.
- value: This parameter holds the value of commands.
Return Value: It returns a Boolean value. If the command is supported then it returns True otherwise returns False.
Example:
<!DOCTYPE html> <html> <head> <title> HTML DOM execCommand() Method </title> <!--script to make text bold--> <script> document.designMode = "on"; function execfunction(event) { document.execCommand("bold"); } </script> </head> <!--onmouseout event when the user moves the mouse pointer after selecting, this execfunction() will execute.--> <body onmouseout = "execfunction(event)"> <h1> Welcome to GeekforGeeks </h1> <h3> Document execCommand() Method </h3> <p> The execCommand() method executes a specified command on selected text or section. </p> <p> Select some text in this page, and move the mouse pointer away from it. It will make the text bold. </p> </body> </html> |
Output:
Before Select the content:

After Select the content:

After Moving Mouse pointer:

Supported Browsers: The browser supported by DOM execCommand() Method are listed below:
- Chrome
- Internet Explorer 9.0
- Opera 29.0
- Firefox 41.0
- Apple Safari 20.0
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM cloneNode() Method
- HTML | DOM isEqualNode() Method
- HTML | DOM isSameNode() Method
- HTML | DOM removeNamedItem() Method
- HTML | DOM click() Method
- HTML | DOM exitFullscreen() Method
- HTML | DOM History go() Method
- HTML | DOM createElement() Method
- HTML | DOM Storage key() Method
- HTML | DOM isDefaultNamespace() Method
- HTML | DOM close() Method
- HTML | DOM hasAttributes() Method
- HTML | DOM createAttribute() Method
- HTML | DOM getBoundingClientRect() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



