HTML and CSS Reference
In-Depth Information
You can make Firefox use the same markup as Chrome and Opera with the
styleWithCSS
command:
execCommand('styleWithCSS', false, false);
Support for more advanced formatting commands tends to be some-
what flaky cross browsers. Nevertheless, these commands can be use-
ful, so we'll look at some of them.
The
formatblock
command allows
you to wrap the current block in a
new element:
execCommand(
'formatblock',false,'<h1>'
);
The
current block
refers to the block-
level parent of the current insertion
point. If you're focused on a
<paragraph>
element, that element
will be converted to the type of
element you specify in the argument.
As ever, watch out for browser inconsistencies. Firefox replaces
the current block element, so a
<p>
becomes an
<h1>
in the previous
example. IE, Chrome, and Opera wrap the old element around the new
one, so the
<p>
ends up containing an
<h1>
.
Only a limited number of elements can be passed in the argument for
formatblock
:
IE
allows
<h1>-6
,
address
, and
pre
. If you want to have more
control over the exact markup inserted, you can use the
inserthtml
command. This means you have to deal with the currently selected text
yourself. Use the
HTML5
text-selection
API
to get the content of the
user's current selection: