How to get current focused element ID?

I want to know the current focused element from the diagram, How can I get the ID ?

from the screenshot you can see that task “B” is focused, I want its ID ?
Thanks in advance.

The Selection service exposes that information.

var selectedElements = modeler.get('selection').get();
// [ { id: 'Foo' }, { id: 'Bar' }, ... ]

I do it by adding a listener to the event bus for the ‘selection.changed’ event.

this.eventBus.on('selection.changed', myFunction);
1 Like