Issue #1077πŸ’¬ AnsweredOpened April 30, 2018by Deepak8132 reactions

How we can remove the selected component html

Quick answerby artf❀ 1

You can do something like this

Read full answer below ↓

Question

Hi artf,

Please let us know how we can remove the selected component html like I have one button html and when i selected that "gjs-comp-selected" class is appended <button class="add_col_btn gjs-comp-selected" id="ir9j">Add New Column</button>

I want to remove this button html and replace with new content on particular event. Please help us to know how we can remove the selected component.

Answers (3)

artfβ€’ May 4, 2018

You can do something like this

const component = editor.getSelected();
const coll = component.collection;
const at = coll.indexOf(component);
coll.remove(component);
return coll.add('<div>New content</div>', { at });
mararn1618β€’ September 23, 2018

This has helped me a lot with programatically removing components and I just want to add some example code in Typescript for further reference.Typescript Example: Dynamically remove components All components are removed that .... have a tagname = exampletag.. have an attribute = exampleattr

Deepak813β€’ May 4, 2018

Hi artf, Thanks for the message and provided code is working fine but i am getting below error: Uncaught TypeError: Cannot read property 'indexOf' of undefined at HTMLDivElement.<anonymous> (template.js?1.15:3784) at HTMLDivElement.dispatch (jquery.min.js:5) at HTMLDivElement.v.handle (jquery.min.j...

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.