Issue #3448Opened May 10, 2021by rcloss0 reactions

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

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 (1)

artfMay 18, 20210 reactions

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'))

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.