Grapesjs: FEAT: Adding custom styles to element using ID.

Created on 23 Jul 2020  路  2Comments  路  Source: artf/grapesjs

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

Most helpful comment

The proper way would be this:

const compById = editor.getWrapper().find('#i9x9h')[0];
compById && compById.addStyle({ 'background-color': '...' });

All 2 comments

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 :) !

The proper way would be this:

const compById = editor.getWrapper().find('#i9x9h')[0];
compById && compById.addStyle({ 'background-color': '...' });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

tribulant picture tribulant  路  3Comments

YashPrince picture YashPrince  路  3Comments

Snarkly picture Snarkly  路  3Comments

nojacko picture nojacko  路  3Comments

alibouaziz picture alibouaziz  路  3Comments