Issue #2541💬 AnsweredOpened January 31, 2020by andy-aware0 reactions

Assign style to class not ID

Quick answerby artf

Just create blocks/components with classes and, by default, the Style Manager will apply styles to them

Read full answer below ↓

Question

What I'm trying to achieve is whenever the "block" inside of the canvas is edited the style isn't added to an #id but instead added to a class. My logic is to take the current ID that is used - the random string and remove it as the ID and make it a class and then assign styles to that class instead of the ID, yes it'll result in lots of classes but it'll mean I won't have issues with ID's on the frontend. I can't seem to find how to do this though, whenever I do it on: editor.on('component:update', component => {}) It just doesn't work. The ID is always undefined. component.getAttributes()['...

Answers (3)

artfFebruary 3, 2020

Just create blocks/components with classes and, by default, the Style Manager will apply styles to them

Fahad-ishfaqJanuary 25, 2024

Just create blocks/components with classes and, by default, the Style Manager will apply styles to them Hi! Can you please tell if we can switch off this behaviour. I want to editor to setup CSS style to element id instead of class names. As same class can be assigned to different elements, which c...

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 →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.