How can we use pasteHTML and editor.getSelectedElement() to paste some html right after the SelectedElement?
So we have to keep the SelectedElement and add the new content after it.
Thanks in advance for your help.
Marc
3 Answers, 1 is accepted
0
Accepted
Rumen
Telerik team
answered on 12 Mar 2021, 11:54 AM
Hi Marc,
You need to collapse the selection. Here is an example:
<telerik:RadEditorID="RadEditor1"runat="server"><Content><div>Div element</div><span>Span element</span></Content></telerik:RadEditor><buttononclick="PasteAfterElem()"unselectable="on">
Click to apply bold over selection</button><scripttype="text/javascript">functionPasteAfterElem() {
var editor = $find("<%=RadEditor1.ClientID%>"); //return a reference to RadEditorvar selectedElement = editor.getSelectedElement();
editor.selectElement(selectedElement);
//Collapse the selection to the end
editor.getSelection().collapse();
editor.pasteHtml("test");
}
</script>
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.