Hi.
I want create a plugin to style text. Its working, but its remove the html in selected text too. (This here is only a very simple example)
here the textarea html content:
<strong>Initial value</strong>
here the code snippet:
(getSelectionHTML taken from viewtopic.php?p=31688#p31688)
function getSelectionHTML(selection) { var range = (document.all ? selection.createRange() : selection.getRangeAt(selection.rangeCount - 1).cloneRange()); if (document.all) { return range.htmlText; } else { var clonedSelection = range.cloneContents(); var div = document.createElement('div'); div.appendChild(clonedSelection); return div.innerHTML; } } var mySelection = editor.getSelection(); var selectedText = getSelectionHTML(mySelection.getNative()); editor.insertHtml('<span style="color:red;">'+selectedText+'</span>');
html content after execute code:
<strong>Initial </strong><span style="color:red;">value</span><strong>.</strong>
"value" is not <strong> anymore. What is my mistake?