Issue #1388✓ SolvedOpened August 27, 2018by froderf3 reactions

Update the style of selected component

Quick answerby artf2

Ok, if you select an element like this: <div id="inul" class='class1'>Hello</div> You have these options:Use editor.getSelected().setStyle({ color: 'red' }) to change only the selected component style, so in result you will get:Change the selected CSS rule style (if one exists) by using editor.getSelectedToStyle().set...

Read full answer below ↓

Question

I'm trying to update the css of selected element. Example: Selected element: <div id="inul" class='class1'>Hello</div> the above code was returned from component.toHTML(); CSS: .class1{ background-color: black; } the above css code was returned from editor.CodeManager.getCode(component, 'css', {cssc: editor.CssComposer}); I used textarea here(for example) and edit the css code and when I hit save button and run the code below editor.getSelected().em.set('style', content); The result is not what it should be it returns #inul { 0: .; 1: w; 2: o; 3: o; 4: m; 5: d; 6: a; 7: 1; 8: 9; 9: 4; 10: 5;...

Answers (3)

👍 Most helpfulartfSeptember 2, 2018

Ok, if you select an element like this: <div id="inul" class='class1'>Hello</div> You have these options:Use editor.getSelected().setStyle({ color: 'red' }) to change only the selected component style, so in result you will get:Change the selected CSS rule style (if one exists) by using editor.getS...

artfSeptember 5, 2018

@froderf when you do .setStyle(content ); content should be an object like { color: 'red' } and not a string with also the selector

froderfAugust 29, 2018

what I need here is something like editor.CodeManager.setCode(component, 'css', {cssc: editor.CssComposer});

which update the style of selected component

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.