timdown / rangy

A cross-browser JavaScript range and selection library.
MIT License
2.25k stars 368 forks source link

Rangy to wrap selected text with single span #409

Open mustufasathaliya opened 8 years ago

mustufasathaliya commented 8 years ago

Hi is there any way to wrap selected text with single span , even if it contain html tag between . For eg my text is

<strong>Hello</strong> test rangy highlighter

Now when i highlight above text , than rangy add two span as below

<strong><span class="highlight">Hello</span></strong><span class="highlight"> test rangy highlighter</span>

But i want that selected text should wrap with single span as

<span class="highlight"><strong>Hello</strong>test rangy highlighter</span>

edsonharantes commented 8 years ago

Did you try using the surroundContents method? Or the Class Applier Module?

mustufasathaliya commented 8 years ago

I had used rangy Class Applier module, but it wrap only the text node. Can you please share me line of code to wrap entire selected content with single span

romanovma commented 5 years ago

I am also curious how this can be done. Say I have paragraphs with different styles and I want them to be applied to the group of text nodes, not separately to each one of them

ItsRyanWu commented 5 years ago

Does anyone have a solution? @romanovma @mustufasathaliya

nishantmendiratta commented 5 years ago

Did you find any solution @mustufasathaliya @edsonharantes @romanovma?

ItsRyanWu commented 4 years ago

The answer is using native Range API. @nishantmendiratta