how to make selected text stay surrounded by a span without breaking any Tag-element (javascript)
one exaple:
original text:
<p> a foo </p>
<p> another bar </p>
selected:
a foo
er bar
anoth
I do not want break the html nesting structure:
<p> a fo<span>o </p>
<p> anoth</span>er bar </p>
I need something like this:
<p> a fo<span>o </span></p>
<p> <span>anoth</span>er bar </p>
Using this excellent treeWalker implementation, here is a jsFiddle. Please let me know if this works for you. Side note, use rangy it is awesome.
EDIT: Nope, wait, fixed.