javascript contentEditable - wrap cross-tag selections
问题 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