FEAT: Adding custom styles to element using ID.
Question
What are you trying to add to GrapesJS? Adding custom styles (like background) to element using ID.
Is there an alternative at the latest version?
[ ] Yes (descripe the alternative) [X] No
Is this related to an issue?
[ ] Yes (Give a link to the issue) [X] No
Answers (2)
The proper way would be this:
const compById = editor.getWrapper().find('#i9x9h')[0];
compById && compById.addStyle({ 'background-color': '...' });
Hi @BerkeAras !
Apparently it is undocumented but editor.Components.allById() might be what you're looking for, eg:
editor.Components.allById()['your-id'].set('style', {'background-color': 'red'});
Hope this will help, cheers :) !
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4496
BUG: setStyle
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? chrome latest versionReproducible demo link...
Issue #2667
link element not append in head element in ediot.canvas #firefox #grapesjs
am trying to add google fonts in web-builder to change the font style for that to import am adding cdn in editor the code works in chrome a...
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 #4654
BUG: Custom component for text node including special characters
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v105 Reproducible demo link https:/...
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.