insertHTML()

This example shows how to use editor.insertHTML(html) to place HTML into the editor. If content is selected, the selection is replaced by the inserted markup.

Example code

<div id="div_editor1"></div>

<script>
    var editor1 = new RichTextEditor("#div_editor1");

    editor1.setHTMLCode("<p>Hello World</p>");

    function btnInsertHTMLCode_1() {
        editor1.insertHTML("Time is" + new Date().toLocaleTimeString())
        editor1.collapse(false);
        editor1.focus();
    }
    function btnInsertHTMLCode_2() {
        editor1.selectDoc(false);//collapse to document end
        editor1.insertHTML("<p>Insert a new paragraph " + new Date().toLocaleTimeString() + "</p>")
        editor1.collapse(false);
        editor1.focus();
    }
</script>

<div class="content-space-t-1 ">
    <button class="ls-secondary" onclick="btnInsertHTMLCode_1();return false;">Insert HTML at the caret</button>
    <button class="ls-cta" onclick="btnInsertHTMLCode_2();return false;">Insert HTML at the end of the document</button>
</div>