I am trying to insert a marker at the beginning of the selection (which I use to place an element on top of the selection).
I got confused in a strange case in Chrome where the selection is cleared when the range.insertNode line is range.insertNode :
$(document).on('mouseup', function (e) { var range = window.getSelection().getRangeAt(0).cloneRange(); range.collapse(true); var markerElement = document.createElement("span"); markerElement.appendChild(document.createTextNode("\ufeff"));
Here is a jsbin example that you can use to try: http://jsbin.com/agojib/1/edit
If you select single , it will clear the selection. Any other choice would be ok.
Note: I am using a modification of the code presented in How to place an item next to user text selection?
source share