Issue #1545✓ SolvedOpened October 28, 2018by crashangelbr2 reactions

How I Get ID From Block?

Quick answerby juanj2

You can use this inside the script to reference the block element. If you want the id you can use this.id. Note that document.getElementById(this.id) == this

Read full answer below ↓

Question

Hi, i have my block and I get print in Div id results from my javascript class component... How i get ID from my block ??? editor.BlockManager.add('test-block', { label: 'Test block', attributes: {class: 'fa fa-text'}, content: { content:'<div id=""></div>', script: function () { console.log(document.getElementById("MyBlockDivIDHere")); uil.add('joystick', { target: document.getElementById("MyBlockDivIDHere"), pos:{left:'0', top:'0', bottom:'0' }, name:'JOY', w:100, multiplicator:1, precision:2, fontColor:'#D4B87B' }); }, style: { width: '100px', height: '100px', 'background-color': 'red', }...

Answers (2)

👍 Most helpfuljuanjOctober 30, 2018

You can use this inside the script to reference the block element. If you want the id you can use this.id. Note that document.getElementById(this.id) == this

lock[bot]November 2, 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.