Issue #3421💬 AnsweredOpened April 29, 2021by ltenti-eventboost2 reactions

How to remove class selector css rule

快速解答by ltenti-eventboost1

It makes sense, now I just have to find a way to add this feature to my builder. Thank you @Ju99ernaut!

Read full answer below ↓

Question

I'm using componentFirst set to true to let my users apply needed style to component they selected.

Selecting a component which is applied a css class specific to the component type, and clicking "Sync" button causes the selector change from the component ID to the relevant css class.

Now I can't find a way to go back and throw away the css rule that has the component class as the selector, hence every new instance of that component has the same style.

Thanks for your help!

Answers (4)

ltenti-eventboostMay 7, 2021

It makes sense, now I just have to find a way to add this feature to my builder. Thank you @Ju99ernaut!

bgrand-chMay 11, 2021

Hello,

For future questions or technical issues, which aren't bugs, GitHub's Discussions tab is the place to be.

Don't forget to close this issue if it is resolved or write a new detailed message in Discussions -> Q&A category (and close this issue).

Thank you for your understanding.

artfMay 6, 2021

Hi @ltenti-eventboost I'm not sure If I understand exactly where is your issue. When you're editing with componentFirst enabled, the editor applies style changes on a component-specific CSS rule (eg. #cmp-id { color: red }). When you hit the "Sync" button, all the styles are moved to the current class selector and those inside the component-specific rule are removed .selected-class { color: red } #cmp-id {}. So, from what you've described seems legit to me but maybe I'm missing something.

ClaudeCodeMay 17, 2026

Thanks for reporting this, @ltenti-eventboost.

Great question about [QUESTION] How to remove class selector css rule. The recommended approach with StyleManager is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. Most operations can be achieved by listening to editor and component events

Common patterns:

// Listen for changes
editor.on('change', () => console.log('something changed'));

// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));

If you're still stuck:

  • Share a minimal CodeSandbox reproduction
  • Include what you've already tried
  • Mention your GrapesJS version
  • The community is here to help!

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 →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.