grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

FEAT: Adding custom styles to element using ID.

Open BerkeAras opened this issue 6 years ago • 2 comments

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

BerkeAras avatar Jul 23 '20 12:07 BerkeAras

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

mcottret avatar Jul 27 '20 10:07 mcottret

The proper way would be this:

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

artf avatar Aug 07 '20 12:08 artf