This is a migrated thread and some comments may be shown as answers.

pasteHTML on certain position

3 Answers 141 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
Fit2Page asked on 11 Mar 2021, 02:30 PM

Hi,

 

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

Sort by
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:RadEditor ID="RadEditor1" runat="server">
    <Content>
        <div>Div element</div>
        <span>Span element</span>
    </Content>
</telerik:RadEditor>
<button onclick="PasteAfterElem()" unselectable="on">
    Click to apply bold over selection</button>
<script type="text/javascript">
    function PasteAfterElem() {
        var editor = $find("<%=RadEditor1.ClientID%>"); //return a reference to RadEditor
        var selectedElement = editor.getSelectedElement();
        editor.selectElement(selectedElement);
        //Collapse the selection to the end
        editor.getSelection().collapse();
        editor.pasteHtml("test");
    }
</script>

You can find more information at https://www.telerik.com/forums/pastehtml-after-node-at-cursor-position

Best Regards,
Rumen
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 16 Mar 2021, 12:29 PM
Thanks Rumen, this works.
0
Rumen
Telerik team
answered on 16 Mar 2021, 01:14 PM

You are welcome, Marc!

 

Regards,
Rumen
Progress Telerik

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/.

Tags
Editor
Asked by
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Rumen
Telerik team
Fit2Page
Top achievements
Rank 2
Bronze
Iron
Iron
Share this question
or