Issue #1389Opened August 28, 2018by mariselvanm0 reactions

Add Attribute to Child Elements in component

Question

This is the component I try to add in Editor.

`

  <div class="page">

            <div class="col1"></div>

            <div class="col2"></div>

         </div> 

`

After adding those components I try to add some computed values to the elements like this,

`

element.on('component:add',function(ele){

      ele.addAttributes({

      'data-top' : topOffset,

      'data-left' : leftOffset,

    });

editor.render();// For render Updated html

});`

But, this code only update the .page component only.

How Can I add those attr into .col1,.col2 elements inside .page component ?

Answers (2)

artfSeptember 2, 20180 reactions

Check here all the methods available for components: https://grapesjs.com/docs/api/component.html

Btw you would something like this

element.on('component:add', component => {
	component.find('.col1, .col2').forEach(comp => {
		comp.addAttributes({ ... });
	});
	
	// YOU DON'T NEED TO RE-RENDER
	// editor.render();
});
lock[bot]September 17, 20190 reactions

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.

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.