Issue #820Opened January 29, 2018by JulyanoF0 reactions

[QUESTION] Change and get value of editor.getSelected() block

Question

How can I change and get the content of current selected block?

Answers (3)

JulyanoFJanuary 30, 20180 reactions

To get content: editor.getSelected().get('content') To set content: editor.getSelected().set('content', 'myhtml')

artfJanuary 30, 20180 reactions

@JulyanoF be aware that content is for static strings (used mainly for custom RTEs) therefore by doing this editor.getSelected().set('content', '<div>TEXT1</div>...') you wouldn't be able to edit inner elements.

const selected = editor.getSelected();

// Get the JSON of the Component
JSON.stringify(selected.toJSON())

// Get its HTML
selected.toHTML();

// Set new components
selected.components('<div>Text1</div><div>Text2</div>')
JulyanoFJanuary 31, 20180 reactions

selected.components()

@artf I don't want to create a new component into the selected block,. I need only edit the content. When I use this method, it is creating a new div into the previous block. How can I avoid it?

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.