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

[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)

artfFebruary 3, 20200 reactions

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

Fahad-ishfaqJanuary 25, 20240 reactions

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.

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.