Answer the question
In order to leave comments, you need to log in
Get positions of selected text in div contenteditable?
The second day I'm steaming. Decided to ask a question here.
There is:
<div contenteditabled="true" class="editor">text, my text. Get selected text, please help me to get position of selected text</div>
Answer the question
In order to leave comments, you need to log in
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?
find positions (beginning and end) of the selected text.
window.getSelection();
Firstly, fix the mistake, contenteditable will be correct
Secondly , here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question