Issue #3448💬 AnsweredOpened May 10, 2021by rcloss0 reactions

Applying custom class to component doesn't seem to be working

快速解答by artf

I also tried editor.CssComposer.setRule('.nolink', {'background-color':'red'}); but that didn't seem to work either setRule is the right API to use and it works, but it creates only the rule, you have also to add the class to the component if you want to see it in canvas (eg. editor.getSelected().addClass('nolink'))

Read full answer below ↓

Question

I'm adding a class on a component when certain conditions aren't met, in this case when there's no href set. I viewed the source and see the "nolink" class in the source but it's not setting the background color to red and I'm not seeing it when inspecting the element, this is how I'm trying to add it, but when I do cc.getAll() I'm not seeing the nolink class so I'm not sure where things are breaking down

var cc = editor.CssComposer; var nolink = editor.SelectorManager.add('nolink'); var rule = editor.CssComposer.add([nolink]); rule.set('style', { 'background-color': 'red' });

I also tried editor.CssComposer.setRule('.nolink', {'background-color':'red'}); but that didn't seem to work either

Answers (2)

artfMay 18, 2021

I also tried editor.CssComposer.setRule('.nolink', {'background-color':'red'}); but that didn't seem to work either

setRule is the right API to use and it works, but it creates only the rule, you have also to add the class to the component if you want to see it in canvas (eg. editor.getSelected().addClass('nolink'))

ClaudeCodeMay 17, 2026

Thanks for reporting this, @rcloss.

Thanks for sharing your report about applying custom class to component doesn't seem to be working. To help the team investigate and prioritize this:

Please provide:

  1. A minimal reproducible example (CodeSandbox/JSFiddle)
  2. Your GrapesJS version number
  3. Browser and OS information
  4. Any error messages from the browser console
  5. Steps to reproduce the issue

What helps most:

  • Minimal code example (not your full project)
  • Screen recording or screenshot showing the issue
  • Expected vs actual behavior clearly stated
  • GrapesJS configuration you're using

With these details, the maintainers can identify and prioritize a fix much faster. The GrapesJS team is very responsive to well-documented issues.

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.