Issue #894πŸ’¬ AnsweredOpened February 23, 2018by alimajed930 reactions

Add a custom attribute

Quick answerby samuelmattos

Hi @alimajed93 try it! editor.BlockManager.get("blockId").attributes.content.customAttribute

Read full answer below ↓

Question

Hi everyone,

I am creating new blocks, when I use the following method: editor.BlockManager.add(blockId, { label: blockLabel, content: {...blockContent, **"customAttribute": "value"**}, attributes: blockAttributes}) I can read the customAttribute using editor.getSelected().get("customAttribute")

How to add this attribute and be able to get it in the same way as above, if the block created has the content in HTML format and not JSON? Per example: content: <div></div>

Thank you in advance!

Answers (3)

samuelmattosβ€’ February 23, 2018

Hi @alimajed93 try it! editor.BlockManager.get("blockId").attributes.content.customAttribute

artfβ€’ March 1, 2018

@alimajed93 I think you're referring to this

<div data-gjs-custom-attribute="value"></div>

so then editor.getSelected().get('custom-attribute')

Be aware that attributes keys in HTML are case insensitive, therefore data-gjs-customAttribute="value" is parsed to customattribute

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.