Issue #1859💬 AnsweredOpened March 5, 2019by MisterFK0 reactions

Change an element type in editor

快速解答by arthuralmeidap

Take a look here: https://grapesjs.com/docs/modules/Traits.html#add-traits-to-components It shows how to add/remove custom traits for existing types. It may help you

Read full answer below ↓

Question

Hi,

In my javascript i already create 2 components (type "A" and type "B) with their own traits. I create a context menu on both elements to switch (in the editor) the selected element from type "A" to type "B" and change the traits in consequence.

I didn't found the way to change the type of an element already insert in the editor. Do you have a function or a solution plz?

Thanks artf !

Answers (3)

MisterFKMarch 8, 2019

Thanks, but i don't want to change the type but i want to change the type of only one selected element... If i change the traits of component, all the others elements with this type will be changed and it's not the purpose.

artfMarch 10, 2019

I didn't found the way to change the type of an element already insert in the editor.

The solution will be the same in case you would like to change a <div> with an <img>... so you remove it and replace it with another component at the same index

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.