Get and Set HTML of RichTextEditor

  • To retrieve the editor HTML, call the editor.getHTMLCode method of the editor instance.
  • The editor.setHTMLCode method can be used to set the Html when the editor is first displayed.
  • The editor.getText method can be used to retrieve the string contents of the editor.

Example code

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

    editor1.setHTMLCode("<p><b>Hello</b> World</p><p>Click the button below to show this HTML code</p>");

    function btngetHTMLCode() {
        alert(editor1.getHTMLCode())
    }

    function btnsetHTMLCode() {
        editor1.setHTMLCode("<h1>editor1.setHTMLCode() sample</h1><p>You clicked the setHTMLCode button at " + new Date() + "</p>")
    }
    function btngetPlainText() {
        alert(editor1.getPlainText())
    }
</script>
<div class="content-space-1">
    <button class="ls-secondary" onclick="btngetHTMLCode();return false;">Get Html Code</button>
    <button class="ls-cta" onclick="btnsetHTMLCode();return false;">Set Html Code</button>
    <button class="ls-secondary" onclick="btngetPlainText();return false;">Get Plain Text</button>
</div>