Add and remove classes programmatically
Question
I want to add and remove classes to a selected element, adding classes is working well, but removing them is not
var componentModel = editor.getSelected();
componentModel.addClass('form-color');
I want to be able to do
componentModel.removeClass('form-color');
But its throwing an error.
I'd be grateful if someone could share the correct syntax
Answers (3)
I'll add removeClass in the next release
Looking at https://github.com/artf/grapesjs/blob/dev/src/dom_components/model/Component.js#L276
I would say removeClass is not implemented.
If you know the other classes I think you can do setClass with an array that don't have the class you want to remove
That worked great, thanks for your help :)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1534
Update property Input value from model style.
@artf I want to update height of the element and want to give a custom height using following code It's working fine and it's update the se...
Issue #1307
Question: To stop dynamically generated classes in grapes Editor
Hi @artf is there any Way to stop dynamically generating classes on reloading editor. let say when i add my custom class i.e "my_class" to...
Issue #1211
Adding a working Import Panel Button without the presets
I want to add the Import button at the panel for importing templates, but I don't want to use the presets. I have already added the followi...
Issue #2008
[Question]The canvas turns dark and unmodifiable on adding a large piece of custom html.
I used to add custom html with editor.addComponent(). It works well at most of the time, but when I try to insert a large piece of HTML whi...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.