Answer the question
In order to leave comments, you need to log in
How to replace selected text with html code?
// выделенный текст
sel = window.getSelection();
// если выделена не пустота
if (sel.rangeCount) {
range = sel.getRangeAt(0);
// удалит выделенный тект
range.deleteContents();
range.insertNode(document.createTextNode(replacementText));
}
Answer the question
In order to leave comments, you need to log in
document.execCommand('insertHTML', false, ' ' + document.getSelection().toString() + ' ');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question