Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Align a Text Using execCommand

Tags:

javascript

when I want to make a selected text as Bold , I should use this code :

edit.document.execCommand("bold", false, "");

But how can i make the align of the text is right , left or center using execCommand ?

like image 540
Black Hawk Avatar asked Feb 03 '26 02:02

Black Hawk


1 Answers

execCommand cannot be used for aligning the elements on the page. However you may take a look at commands like Justify or Indent if it will serve your purpose

edit.document.execCommand("JustifyRight", false, "");

https://developer.mozilla.org/en/docs/Web/API/Document/execCommand http://codepen.io/netsi1964/full/QbLLGW/

like image 104
Agney Avatar answered Feb 05 '26 14:02

Agney