Documentation / Get Started

Set content

Initial content #

The editor replaces a textarea or div element on the page, so HTML set for this element will be the editable content.


// element
<textarea id="entry">
    <p>Content</p>
</textarea>

// call editor
Redactor('#entry');

Content in setting #

You can also use the content setting instead of specifying html code inside textarea or div.


// element
<textarea id="entry"></textarea>

// call editor
Redactor('#entry', {
    content: '...your html code..'
});

See example with demo of content setting.

JSON Data #

You can set data as JSON in Redactor. See more examples and descriptions about this:

API method #

Content can be set programmatically using the API method editor.setContent. This method completely replaces the content of the editor with the HTML specified in the argument.

// call editor
let app = Redactor('#entry');

// set content from outside scripts
app.editor.setContent({ html: '<p>Hello world!</p>' });

// set content in the plugin method
this.app.editor.setContent({ html: '<p>Hello world!</p>' });

See more how the API works.

Insert content #

The API method editor.insertContent adds the specified HTML to the cursor position if it is an editable block. If the block is not editable, such as Image, Embed, then the content will be added after the block.

// cal editor
let app = Redactor('#entry');

// insert content from outside scripts
app.editor.insertContent({ html: '<p>Hello world!</p>' });

// insert content in the plugin method
this.app.editor.insertContent({ html: '<p>Hello world!</p>' });

See more how the API works.