Get and set content

This example shows how to use API for getting and setting the HTML content.

API Commands (see browser console)

Code

<!-- buttons -->
<button onclick="getContent(event)">getContent</button>
<button onclick="setContent(event)">setContent</button>

<!-- element -->
<textarea id="entry">...</textarea>

<!-- call -->
<script>
let app = Redactor('#entry');

function setContent(e) {
    e.preventDefault();
    e.stopPropagation();

    app.editor.setContent({ html: '<p>Here is it! I am set.</p>', caret: 'end' });
}

function getContent(e) {
    e.preventDefault();

    let html = app.editor.getContent();
    console.log(html);
}
</script>