1

I have a div in the editor of FF :

<div align='right'>asdasd</div>

and

<div style="text-align:right">asdasd</div>

When I select either of these and fire this command using JS :

document.execCommand('removeformat',false,null);

These justifications are not removed. WHile this happens on Chrome.

Bhumi Singhal
  • 8,063
  • 10
  • 50
  • 76

1 Answers1

3

First, take a look on Stack Overflow question Javascript: execCommand(“removeformat”) doesn't strip h2 tag and its answers.

The editing command removeFormat does in Chrome more than it should do according to currently last proposal of HTML Editing APIs. The div element is not listed as editable HTML element with local name. And text alignment is also not listed on point 7 listing the formatting properties which should be reset by this command.

The editing command removeFormat is proposed for removing formatting from text and not from blocks (paragraphs).

But the behavior of Chrome is nevertheless not wrong as at the moment (2015-01-25) there is no official standard for the HTML Editing APIs and command removeFormat. So every browser can have implemented whatever the developers of this browser thought is useful for this command.

You better code the removing of text alignment property with other methods of JavaScript.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143