0

I am making a custom plugin for the rich texteditor which sets a span with a certain class to a selected text, like: <span class="myclass">text</span>

Ok, so pretend I have the following text:

This is a test.

Now after selecting test and clicking the button to trigger my plugin it will output:

This is a <span class="myclass">test</span>.

Now after this I select the whole text and click the button again, this will output:

<span class="myclass">This is a <span class="myclass">test</span>.</span>

Any idea how to fix this?

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
MHarteveld
  • 167
  • 2
  • 8

1 Answers1

0

You could use my Rangy library and its class applier module.

var applier = rangy.createCssClassApplier("myclass");
applier.applyToSelection();
Tim Down
  • 318,141
  • 75
  • 454
  • 536