Issue #2101Opened June 26, 2019by prabha-9121 reactions

selected content parent tag remove

Question

https://github.com/artf/grapesjs/issues/906#issuecomment-381403858

I need to remove the html content from editor.getSelected(). Now I'm using,

var selectedContent = editor.getSelected();
selectedContent.set('content', '');
selectedContent.components(MYHTML);

While I use selectedContent.set('content', ''); it remove all the inner html. But didn't remove the parent tag. For example, Before: <h2 id="it4a"><p>Sample Update Check Done</p></h2> After: <h2 id="it4a"></h2>

After set the components, its like <h2 id="it4a">NEW HTML</h2>. How to remove the parent tags while set the innerHtml empty?

Guide me how to solve this?

Answers (3)

afdallahJune 27, 20191 reactions

Have you seen this #1077 answer by @artf I think it's suited with your case.

const component = editor.getSelected();
const coll = component.collection;
const at = coll.indexOf(component);
coll.remove(component);
return coll.add('<div>New content</div>', { at });
prabha-912June 27, 20190 reactions

Yeah I tried @afdallah, It returns indexOf undefined. Let me try again. Thanks for your response :)

prabha-912June 27, 20190 reactions

Hi @afdallah @artf I tried the above concept. It works fine in first time. While I try to update second time, it didn't work. indexOf

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.