With window.getSelection, how do I know affect text from two different nodes?
<p>I have this code with which I put selected text inside a span that gives it a background-color with CSS.
When I try to 'mark' text from two different divs, or text which is inside any two tags, I get an error:
<code>Uncaught Error: BAD_BOUNDARYPOINTS_ERR: DOM Range Exception 1</code></p>

<p>This is my code:</p>

<pre><code>function highlightSelection()   {
var selection;



//Get the selected stuff
    if(window.getSelection) 
        selection = window.getSelection();
    else if(typeof document.selection!="undefined")
        selection = document.selection;

    //Get a the selected content, in a range object
    var range = selection.getRangeAt(0);

    //If the range spans some text, and inside a tag, set its css class.
    if(range &amp;&amp; !selection.isCollapsed)
    {
            var span = document.createElement('span');
            span.className = 'highlight-green';
            range.surroundContents(span);
    }
}
</code></pre>

<p>The highlightSelection() is called with <code>onmouseup</code> event.
Thanks ahead!</p>
