All documentation ↓← All docs

editor.getEditable(bFocus)

Returns the editable root element — the body inside the editor’s iframe that actually holds the content the user types into. Reach for it when you need the container element itself: to read its children, measure it, or scope a query to just the edited content.

Syntax

editor.getEditable(bFocus)

Parameters

bFocus — optional boolean. When true, the editor is focused before the element is returned. Omit it (or pass a falsy value) to get the element without changing focus.

Returns

The editable body element.

Behavior notes

  • Element, not document. This returns the body element; getDocument() returns the surrounding Document. Both live inside the editing iframe.
  • Optional focus is a convenience. Passing true saves a separate focus() call when you are about to place a selection or start editing.
  • Query against it to stay scoped. A querySelector on the returned element only ever sees the edited content, never the surrounding page chrome.

Example usage

Read the first paragraph of the edited content:

Code example
var editor1 = new RichTextEditor("#div_editor1");
var body = editor1.getEditable();
var firstPara = body.querySelector("p");

Focus the editor and get the editable in one call before setting a selection:

Code example
var body = editor1.getEditable(true);   // focuses, then returns the element

Related

Calling editor.getEditable() from your app

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

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

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.