editor.getDocument()
Returns the Document object of the editor’s editing area. The content you edit lives inside an iframe, so this is that iframe’s document — not the outer page document. Use it whenever you need to run DOM operations (queries, ranges, created nodes) against the edited content itself.
Syntax
editor.getDocument()
Parameters
None.
Returns
The editing iframe’s Document.
Behavior notes
- It is the iframe document, not the page. The editor renders its content in an isolated iframe. A
document.querySelectoron the outer page will not find nodes inside the editor — queryeditor.getDocument()instead. - Create nodes from this document. Elements and ranges you intend to insert into the editor should be created with
editor.getDocument().createElement(...)/createRange()so they belong to the right document. - Pair it with getEditable() when you want the editable body element rather than the whole document.
Example usage
Count the images in the edited content (scoped to the editor, not the page):
var editor1 = new RichTextEditor("#div_editor1");
var doc = editor1.getDocument();
var imageCount = doc.querySelectorAll("img").length;Build a node from the editor’s document before inserting it:
var doc = editor1.getDocument();
var hr = doc.createElement("hr");
editor1.insertElement(hr);Related
- editor.getEditable()— the editable body element inside this document.
- editor.insertElement(element)— insert a node you built from this document.
- editor.getSelection()— the current selection within it.
Calling editor.getDocument() from your app
editor.getDocument() 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
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.getDocument();React and Next.js
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);
function onClick() {
editorRef.current?.getDocument();
}
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.currenttonullin between. UseeditorRef.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.