How to change id/class when new element drop on editor or render element with dynamic ip?
In your block:drag:stop callback you should make a change to the droppedComponent (is an instance of Component, so use its API), the $('#staticId') doesn't even exist, the canvas is in the other frame of the document.
Read full answer below βQuestion
Hello @artf , Hope you are doing well. I have two questions regards dynamic blocks adding, 1) Is it possible to render the block with dynamic id? 2) Is it possible to change the id/class/onClick methods in block:drag:stop or component:add grapesjs methods? Here is some of my code, In above example i need to make dynamic instead of staticId. Which is also passed into the onclick function as well. I am trying to change that id inside the But after the change with the help of $('#staticId').attr('id', 'random id is here'); it's not getting change actually. Actually i am using grapes.js with angu...
Answers (3)
In your block:drag:stop callback you should make a change to the droppedComponent (is an instance of Component, so use its API), the $('#staticId') doesn't even exist, the canvas is in the other frame of the document.
Hello @artf, Thank you for your quick support. It's working for me now, This is worked for me. Suppose i have content like, Is there any possibilities to update img tag's id and onclick function?
@AkibDeraiya123 you can do whatever you want, check the API please https://grapesjs.com/docs/api/component.html
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1951
[QUESTIONS] change or add event on add component from block
is it possible ?, change the drag and drop event to on click when adding a new component, I want to add components by clicking the block th...
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
Issue #1674
Render block after trait action .
I have created new block called sidebar that have dynamic updates by trait component ,trait contain checkboxes to dynamic change content by...
Issue #1111
How to add parent class when drag element
Hi @artf, Hope you are doing fine. Please let us know how we can add the parent class of div when new element is dragged inside that div li...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.