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)
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');
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
@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.
Issue #1077
How we can remove the selected component html
Hi artf, Please let us know how we can remove the selected component html like I have one button html and when i selected that "gjs-comp-se...
Issue #1061
How we can show countdown traits
Hi artf, Please let us know how we get the countdown elements in edit mode means when we set the template html using editor.setComponents(t...
Issue #1105
add class in existing element
Hello previous issue can you please let me know how can add a new class on map element? I don't want add class manually on element through...
Issue #771
Image src is not updating
Hi @artf, I have updated the image src using below code: editor.getSelected().set('attributes', {'src': image_Url}); but when i set all the...
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.