Get an added block

This example shows how to get instance of inserted block in the editor. Click add (+) icon on the toolbar, paste some block and see the result in the browser console.

Code

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

<!-- call -->
<script>
let app = Redactor('#entry', {
    subscribe: {
        'block.add': function(event) {
            let instance = event.get('inserted');
            if (instance.isType('text')) {
                let $block = instance.getBlock();

                // example of manipulation of a block
                $block.html('My text');

                // set caret to the end
                let caret = this.app.create('caret');
                caret.set($block, 'end')
            }
        }
    }
});
</script>