[Question] Assign style to class not ID
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()['id']; and I don't seem to be able to reassign the style set to that ID to a unique class.
I know this sounds silly, but my issue comes when I'm using some Javascript on the frontend of my site and it's throwing a wobbler when it duplicates the HTML for an infinite scroller. Multiple ID's on the page is incorrect and making it into a class would work much better.
Answers (3)
Just create blocks/components with classes and, by default, the Style Manager will apply styles to them
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 cause change to styles of all elements.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2706
[QUESTION] Unique ID on block content without inline style
Hi All, I made a custom block manager element, but when the element is edited, it applies the style to the class, which means all the same...
Issue #2378
[QUESTION] Modifying global CSS in style manager
We want to achieve the following:Mark our block HTML elements with some classes like:Add some styles that define CSS classes like:Using Gra...
Issue #3067
FEAT: remove 'display: block' inline style from Style Manager sectors and properties
What are you trying to add to GrapesJS? Improve visibility for Style Manager sectors and properties. Describe your feature request detailed...
Issue #2836
[BUG]: Unable to add class when adding Dom Component
GrapesJS Version used: 0.16.12 (current) Just a strange behavior, I can add all the attributes I want when adding component directly inside...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.