Issue #740💬 AnsweredOpened January 10, 2018by Deepak8130 reactions

How to remove class from html

Quick answerby ryandeba

Hi @Deepak813, Components have a setClass method that will remove all existing classes an replace them with the string of classes passed as the first argument. Try this: editor.getSelected().setClass('newClass');

Read full answer below ↓

Question

Hi @artf,

We are updating the <i> tag class but it adds new class to this but previous class is not remove.please let us know how to remove class.

using this : editor.getSelected().set('attributes', {'class': 'newClass'});

Output: <i class="fa fa-smile-o c2515" class="fa fa-address-book-o">

but "fa fa-smile-o" is not removed.

Look forward for positive response.

Answers (3)

ryandebaJanuary 10, 2018

Hi @Deepak813,

Components have a setClass method that will remove all existing classes an replace them with the string of classes passed as the first argument. Try this: editor.getSelected().setClass('newClass');

Deepak813January 10, 2018

Hi @ryandeba,

Thanks for the message.

I have already used this but its showing following error:

----------Uncaught TypeError: editor.getSelected(...).setClass is not a function------------------

Please let us know how to remove this error to resolve the issue.

Thanks

ryandebaJanuary 10, 2018

@Deepak813 - The code I provided works just fine for me in the demo, so I suspect that there must be something about your configuration that is causing the issue. Could you make sure you're on the latest version of grapesjs and then create a jsfiddle that shows the problem if you're still having is...

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 →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.