execCommand setting css class in a WYSIWYG editor

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I've been trying to edit an inbrowser WYSIWYG editor that relies on
execCommand for most of its operations.

I would like a dropdown of styles that a user can choose and are applied
to the outer tag of their current selection.

I've created the following by editing an example I found online but it
only works in IE:

function SelectClass(selectname) {
    if (selectname.selectedIndex != 0) {
    selectname.selectedIndex = 0;
    if (browser.isIE5up) {
        sel = EpozElement.contentWindow.document.selection;
        range = sel.createRange();
        el = range.parentElement();
        sel = EpozElement.contentWindow.window.getSelection();
        range = sel.getRangeAt(0);
        el = range.parentNode;
    if (option != 'none') {
        el.className = option;
    if (option == 'none') {

I've tried a few things but I can't work out what the Mozilla equivalent
to range.parentElement() is.

If anyone can see how I can get that to work in Mozilla, or knows of a
way to do this using execCommand then that'd be much appriciated


Re: execCommand setting css class in a WYSIWYG editor

Andrew Crowe wrote:

Quoted text here. Click to load it

try this:

} else if (browser == "Mozilla") {
    sel = EpozElement.contentWindow.window.getSelection();
    el = sel.anchorNode;

icq 169389999

Site Timeline