Documentation

editor.getHTMLCode()

Returns the editor’s content as an HTML string — the clean markup you save to your database or send to your API. It is the counterpart to setHTMLCode(), and is also available under the alias editor.getHTML().

Syntax

editor.getHTMLCode()

Parameters

None.

Returns

The content as an HTML string.

Behavior notes

  • Trailing empty blocks are trimmed. A dangling empty paragraph left by the caret at the end of the document is not included, so saved content does not accumulate stray blank blocks.
  • It respects code view. While the editor is showing HTML source, getHTMLCode() returns exactly what is in the code view, so you always read what the user currently sees.
  • Text and comments are preserved.Element markup, HTML comments, and encoded text nodes are all included — the result is faithful, publish-ready HTML.

Example usage

Save the content on submit:

var editor1 = new RichTextEditor("#div_editor1");
document.getElementById("btn_save").onclick = function () {
    var html = editor1.getHTMLCode();
    fetch("/api/save", { method: "POST", body: html });
};

Round-trip content in and back out:

editor1.setHTMLCode("<p>Hello <b>world</b></p>");
var html = editor1.getHTMLCode();   // "<p>Hello <b>world</b></p>"

Related