Issue #698πŸ’¬ AnsweredOpened January 2, 2018by alimajed930 reactions

Editor.getSelected().toHTML() is not consistent

Quick answerby artf

Inside your html-block component create a new property (eg. custom-code) for user's code and retrieve it with editor.getSelected().get('custom-code')

Read full answer below ↓

Question

Hi everyone, I created a new component type, 'html-block', which is a component in which you can add your html code. I added an 'Edit' button to the toolbar, to enable the user editing the added html code. In order to show the html code of the component in the modal, I am using the function 'editor.getSelected().toHTML()'; The problem is that, sometimes the code returned is per example: <div><h1>h1</h1></div> (which is what I need, since I need the exact code that the user added at first), and sometimes it returns something like that: <div id='135'><h1>h1</h1></div> (with an id added automati...

Answers (3)

artfβ€’ January 4, 2018

Inside your html-block component create a new property (eg. custom-code) for user's code and retrieve it with editor.getSelected().get('custom-code')

alimajed93β€’ January 4, 2018

This solved the problem for me. Thank you.

lock[bot]β€’ September 18, 2019

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

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.