All documentation ↓← All docs

editor.setHTMLCode()

This method is used for setting the content of RichTextEditor.

Syntax

editor.setHTMLCode(strHTMLCode)

Parameter

Type: String

The string that will overwrite the content of editor.

Options (optional, core 2.6.10+)

editor.setHTMLCode(html, { undoable: true }) records the current content as an undo step first, so Ctrl+Z brings it back. Without it, the new content becomes the starting point of the undo history (what you want when loading a document; not when replacing one the user was editing).

Example usage

Code example
var editor1 = new RichTextEditor("#div_editor1");      
      
editor1.setHTMLCode("<p><b>Hello</b> World</p>"); 

Related

Calling editor.setHTMLCode() from your app

editor.setHTMLCode() belongs to the editor instance. Every integration below works the same way: keep the object that new RichTextEditor(...) returns, and call it on that object.

Plain JavaScript

Code example
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.setHTMLCode();

React and Next.js

Code example
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);

function onClick() {
  editorRef.current?.setHTMLCode();
}

return <RichTextEditor editorRef={editorRef} />;

In Vue and Angular, the wrapper components in the guides keep the instance in a component variable (editor), so the call is the same. See the React, Vue and Angular pages, or download a tested project from the guides.

If the editor is undefined

  • The call ran before the component mounted. Call it from an event handler or after the mount effect has run.
  • In React development mode, Strict Mode mounts, unmounts and mounts again, so the wrapper sets editorRef.current to null in between. Use editorRef.current?. rather than storing the instance elsewhere.
  • The editor was destroyed (editor.destroy()) when its component unmounted.

All methods: method reference · all events: event reference.