Issue #2914Opened July 23, 2020by BerkeAras3 reactions

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)

artfAugust 7, 20202 reactions

The proper way would be this:

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

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.

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.