HTML-formatted selected text returns whitespace from a range selection
<p>I have a Javascript routine that retrieves the selection text by a user formatted as HTML:</p>

<pre><code>function getHTMLOfSelection() {
    var range;
    if (document.selection &amp;&amp; document.selection.createRange) {
        range = document.selection.createRange();
        return range.htmlText;
    }
    else if (window.getSelection) {
        var selection = window.getSelection();
        if (selection.rangeCount &gt; 0) {
            range = selection.getRangeAt(0);
            var clonedSelection = range.cloneContents();
            var div = document.createElement('div');
            div.appendChild(clonedSelection);
            return div.innerHTML;
        }
        else {
            return '';
        }
    }
    else {
        return '';
    }
}
</code></pre>

<p>With the fiddle, make sure and select the quoted text first:</p>

<p><a href="http://jsfiddle.net/userdude/Y4BBq/13/" rel="nofollow">http://jsfiddle.net/userdude/Y4BBq/13/</a></p>

<p>The code works fine, however, the selection includes a <code>\r\n</code> after every <code>&lt;/p&gt;</code> and <code>&lt;br/&gt;</code>.
Why are these added and at what point? It seems redundant, as the <code>&lt;p&gt;</code> and <code>&lt;br&gt;</code> tags already include the new line.</p>
