<div contenteditabled="true" class="editor">text, my text. Get selected text, please help me to get position of selected text</div>
function changeSelected(){
if (window.getSelection() == '') {
return false;
}
var range = window.getSelection().getRangeAt(0);
var selectionContents = range.extractContents();
var span = document.createElement("span");
span.appendChild(selectionContents);
span.setAttribute("class", "selected");
span.style.backgroundColor = "yellow";
span.style.color = "green";
range.insertNode(span);
}
document.selection?
найти позиции (начало и конец) выделенного текста.
window.getSelection();