Add new class programatically
See original GitHub issueHello Artf,
I want to edit the styles of components (mostly imported html) without modifying all components with the same class. I tried to add a random named class programmatically like this: ` this.editor.on(‘component:selected’, function(model) { if (model && model.length > 2) { const uuid = this.s4(); // generate new random class name
const selector = {
name: uuid,
type: 'class',
label: uuid,
};
model[1].attributes.classes.push(selectorManager.get(uuid));
let mClasees = model[1].attributes.classes;
const uuid = this.s4();
const selector = {
name: uuid,
type: 'class',
label: uuid,
};
mClasees.push(selector);
}.bind(this)); `
This add a class programmatically to the component but it seem to no let me edit it’s style.
I just want be able to change the style of a single component without having to care which class it belongs to. Event if I copy past a component, I want be able to edit each components individually. I hope that clear. If you need any further information, don’t hesitate to ask me 😃 Thanks your help!
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to dynamically change CSS class of an HTML tag?
You can add a CSS class based on id dynamically using classList API as follows: document.getElementById('idOfElement').
Read more >How to dynamically create and apply CSS class in JavaScript
After adding new classes to the elements, we select the new class(test) and then apply CSS properties to it, with the help of...
Read more >Dynamically add CSS class with JavaScript - Includehelp.com
In this post, we will learn how to dynamically add CSS class with JavaScript code. It is useful to add interactive dynamic functionality?...
Read more >How to Create a Class Dynamically in C#? - Code Maze
In this article, we are going to learn how to create a class dynamically in C#. Thanks to the introduction of the dynamic...
Read more >How to Dynamically Add a Class Name in Vue
Adding a dynamic class name is as simple as adding the prop :class="classname" to your component. Whatever classname evaluates to will be the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@wemod123
editor.getWrapper().addClass('my-class')
@IrinaCodixis from the https://github.com/artf/grapesjs/releases/tag/v0.14.52 we’ve added
setRule
/getRule
methods, so to add some CSS rule programatically you should do this: