I have a text like
<AnyTag>here is a sample test text and more text</AnyTag>.
Now I am selecting "test" and clicking an italic button in my page and it creates a new element <span class="ItalicClass">
and it surroundContents()
. This woks fine.
Now I have text like
<AnyTag>here is a <i>sample test text</i> and more text</AnyTag>.
Now if I select "test" it does the same but I would like to close the parent first and then insert the new element. I know the parentNode
hence I can insert a new class in the span
element. Same way I need to open the same parent after the end of new element. The the final line should be
<AnyTag>here is a <i>sample </i><span class="ClassB">test</span><i> text</i> and more text</AnyTag>
If I select the word "more" then
<AnyTag>here is a <i>sample test text</i> and <span class="ClassA">more</span> text</AnyTag>.
Appreciate any pointers in this regard.
Regards Dominic