Javascript surroundContents on selection doesn't work as expected if used on part of an already selected element
问题 I 'de like to higlight text selected by the user and copy it over to a text box. The latter part works great. But highlighting of the selected text fails if I try to highlight part of an already highlighted text. Here's a JSFiddle Try selecting the text on the right box, then try to select part of your previous selection. Any ideas? The relevant code: function highlightSelected() { var selection = getSelected(); var range = selection.getRangeAt(0); var newNode = document.createElement("span")