5

The following DHTML formatting commands each work fine on a div with contentEditable=true in IE, Firefox and Chrome:

document.execCommand("superscript", false, null);
document.execCommand("subscript", false, null);

However, calling the command again to remove the formatting has no effect in Chrome.

Am I missing something or is this a bug in Chrome?

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • Works for me for the simple cases I've tried. Could you post a test case? – Tim Down Mar 06 '11 at 12:15
  • Hm, there must be a conflict in my spaghetti-code implementation. [Test on jsFiddle](http://jsfiddle.net/8RWfe/) works. – Petrus Theron Mar 06 '11 at 14:14
  • I get the same thing when trying to remove superscript using the Redactor wysiwyg with a custom button. It does however work in a basic contenteditable. A real head scratcher. – Michael Bylstra Dec 13 '12 at 11:16

1 Answers1

7

I had a similar problem. For me, the problem was due to some "normalization" CSS altering vertical-align: baseline for sup and sub tags. Overriding that CSS and setting sub to vertical-align: sub and sup to vertical-align: super fixed it.

Jonathan B
  • 181
  • 1
  • 2
  • 1
    Excellent catch that saved me undoubtedly many hours of work trying to figure out wtf was wrong. – Puppy Apr 15 '15 at 15:48