Save and restore selection

This example shows how to save and restore selection with API.

Select some text and click to buttons.


Code

<!-- api buttons -->
<button onclick="saveSelection(event);">Save</button>
<button onclick="restoreSelection(event);">Restore</button>

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

<!-- call -->
<script>
var app = RedactorX('#entry');

function saveSelection(e) {
    e.preventDefault();
    e.stopPropagation();
    app.selection.save();
}

function restoreSelection(e) {
    e.preventDefault();
    e.stopPropagation();
    app.selection.restore();
}
</script>