question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add and remove classes programmatically

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
artfcommented, Dec 19, 2017

I’ll add removeClass in the next release

1reaction
juanjcommented, Dec 18, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Remove a Class Name - W3Schools
Learn how to remove a class name from an element with JavaScript. Remove Class. Click the button to remove a class from me!...
Read more >
React: Programmatically Add/Remove CSS Classes
This succinct, practical article shows you how programmatically add/remove CSS classes to/from an element in React.
Read more >
javascript dynamically adding and removing classes [duplicate]
I am working on a simple example, if a user clicks on element then all the elements above it should have a class...
Read more >
How to add/remove css class programmatically? - Mendix Forum
Hi Gatis,. I think widget ShowByCondition should help in your usecase! Adding classes is something most widgets and Mendix by default ...
Read more >
How To Add Or Remove a Class With JavaScript - YouTube
In this tutorial, you'll learn how to add or remove a class on a HTML element using JavaScript. Get my free 32 page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found