I'm experimenting a bit with contentEditable
and encountered this issue: I have the following js snippet
var range = document.getSelection().getRangeAt(0);
var newNode = document.createElement("span");
newNode.className = "customStyle";
range.surroundContents(newNode);
and this HTML fragment:
<ul>
<li>the <b>only entry</b> of the list</li>
</ul>
<p>Some text here in paragraph</p>
The js code allows to wrap the current selection with a <span>
tag.
It works perfectly when the selection includes whole HTML tags (e.g. selecting 'the only entry of') but not, of course, when the selection includes only one of their endings (e.g. selecting from 'entry' to 'Some', both included).
Though I'm aware this problem is not trivial, I'm looking for suggestions about the best approach. Thanks in advance!
Some
`. Tim Down's answer and solution would do pretty well! – ilPittiz Apr 15 '15 at 17:08