document.execCommand('heading' ..') in Chrome

Viewed 3843

I'm trying to use the rich-text editing command functions as described in MDN here

The API for this seems fairly simple. Select some text, and execute the command, and it'll wrap the content with it. Cool stuff!

In Firefox (Aurora), this works great:

document.execCommand('heading', false, 'H1');

However the same command in Chrome returns nothing. Is this not implemented the same way (or at all) in Chrome?

Thanks!

3 Answers

You can create it with three moves, like this...

var S=window.getSelection();

document.execCommand('delete',false,'');

document.execCommand('insertHTML',false,'<h1>'+S+'</h1>');
Related