Sidenote: Now this is truly weird. I commented out my code. After I reload the div I have it select all the contents of the div, like this:
$('#right div.text').each(function() { window.getSelection().removeAllRanges(); var range = document.createRange(); range.selectNodeContents(this); window.getSelection().addRange(range); }); What happens? The entire div is selected and then the selection goes away and is replaced by an insertion cursor in the beginning of the div! What the heck is this all about?