grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

ho to change style of added dom element

Open altalker opened this issue 9 years ago • 3 comments

I added text h2 title: var domc = editor.DomComponents; var comp1 = domc.addComponent({ tagName: 'h2', type:'text', removable: true, // Can't remove it draggable: true, // Can't move it copyable: true, // Disable copy/past content: title, // Text inside component style: { color: 'red' }, attributes: { title: 'title',id:'header' } });

I need to change the color after adding item. How do I change the color and background css?

altalker avatar Jul 12 '17 23:07 altalker

You can make use of this listener

editor.on('component:add', function(model) {
 // ... put some check logic
 model.set('style', { color: 'blue' });
})

artf avatar Jul 13 '17 18:07 artf

What I am struggling with is with changing values of DOM Components after reloading of the Canvas. var comps = editor.DomComponents; var hType = comps.getType('div'); I am trying to get the exact component by ID not by Type var mmodel = hType.model; error- does not work mmodel.set('style', { color: $("Color").val() });

altalker avatar Jul 14 '17 05:07 altalker

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 18 '19 16:09 lock[bot]