All documentation ↓← All docs

editor.getPlainText()

Returns the editor’s content as plain text, with all HTML formatting removed. Use it for a text preview, a search index, an excerpt, or a character/word count — anywhere you want the words without the markup. It is also available under the alias editor.getText().

Syntax

editor.getPlainText()

Parameters

None.

Returns

The content as a plain-text string.

Behavior notes

  • Rendered text, not raw markup.The result is the visible text of the content — block structure appears as line breaks, and formatting tags are dropped. For the HTML itself, use getHTMLCode().
  • getText() is an alias. editor.getText() and editor.getPlainText() return the same value.
  • Round-trips with setPlainText. editor.setPlainText(value) replaces the content with plain text the same way.

Example usage

Build a short excerpt for a list view:

Code example
var editor1 = new RichTextEditor("#div_editor1");
var text = editor1.getPlainText();
var excerpt = text.slice(0, 140) + (text.length > 140 ? "..." : "");

Show a live character count:

Code example
console.log(editor1.getPlainText().length + " characters");

Related

Calling editor.getPlainText() from your app

editor.getPlainText() 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.getPlainText();

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?.getPlainText();
}

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.