Move selection after a DOM element
The problem is that WebKit has fixed ideas about where the caret (or a selection boundary) can go and is selecting an amended version of your range when you call the selection's addRange()
method. I've written about this a few times on Stack Overflow; here are a couple of examples: