Documentation

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.querySelector on the outer page will not find nodes inside the editor — query editor.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