Issue #1545Opened October 28, 2018by crashangelbr2 reactions

[Question] How I Get ID From Block?

Question

Code SnippetTEXT
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)

juanjOctober 30, 20182 reactions

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, 20190 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.