Issue #1683πŸ’¬ AnsweredOpened December 26, 2018by AkibDeraiya1230 reactions

How to change id/class when new element drop on editor or render element with dynamic ip?

Quick answerby artf

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)

artfβ€’ December 27, 2018

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.

AkibDeraiya123β€’ December 27, 2018

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?

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

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.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.