Issue #740Opened January 10, 2018by Deepak8130 reactions

How to remove class from html

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, 20180 reactions

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, 20180 reactions

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, 20180 reactions

@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 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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.