# Adding overlays that DON'T prevent mouse events being captured by the underlying element

**URL:** <https://forum.bpmn.io/t/adding-overlays-that-dont-prevent-mouse-events-being-captured-by-the-underlying-element/14375>\
**Category:** Developers\
**Created:** [February 14, 2025, 1:20pm UTC](https://forum.bpmn.io/t/adding-overlays-that-dont-prevent-mouse-events-being-captured-by-the-underlying-element/14375 "2025-02-14T13:20:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinisa.rudan](https://forum.bpmn.io/user_avatar/forum.bpmn.io/sinisa.rudan/32/2005_2.png) [@sinisa.rudan](https://forum.bpmn.io/u/sinisa.rudan)\
**Post date:** [February 14, 2025, 1:20pm UTC](https://forum.bpmn.io/t/adding-overlays-that-dont-prevent-mouse-events-being-captured-by-the-underlying-element/14375/1 "2025-02-14T13:20:45Z")

</div>

Is there a way to add an overlay over an element that would NOT prevent mouse events being captured by the underlying element?

in the related question [Event with overlay in a task](https://forum.bpmn.io/t/event-with-overlay-in-a-task/2777)  
moderator @philippfromme suggested  
`pointer-events: none `

Unfortunately, this doesn’t work because [BPMN.io](http://bpmn.io/) wraps our overlay in another div that captures mouse events.

Isn’t there an option on overlays adding to choose the case where we want it to happen? that would add `pointer-events: none `to that embedding div?

---

<div class="post-metadata">

**Author:** ![sinisa.rudan](https://forum.bpmn.io/user_avatar/forum.bpmn.io/sinisa.rudan/32/2005_2.png) [@sinisa.rudan](https://forum.bpmn.io/u/sinisa.rudan)\
**Post date:** [February 16, 2025, 10:01am UTC](https://forum.bpmn.io/t/adding-overlays-that-dont-prevent-mouse-events-being-captured-by-the-underlying-element/14375/2 "2025-02-16T10:01:52Z")

</div>

I’ve solved it myself through a CSS-workaround (until the systemic solution is provided by [BPMN.io](http://BPMN.io)):

CSS:

```css
.highlight-overlay {
    background-color: blue; /* color elements as green */
    opacity: 0.2;
    border-radius: 10px;
    pointer-events: none; /* no pointer events, allows clicking through onto the element */
}
// preventing div, that is added by BPMN.IO as a wrapper around any of ours overlays, from catching mouse events
.djs-overlay:has(.highlight-overlay) {
    pointer-events: none;
}

```

adding the overlay:

```typescript
const diagram: BpmnModeler | BpmnViewer;
...

const elementRegistry = diagram.get('elementRegistry');

const shape = elementRegistry.get(elementId);

const overlayHtml: HTMLDivElement = Object.assign(document.createElement('div'), {
			className: 'highlight-overlay',
			style: `width: ${shape.width}px; height: ${shape.height}px; pointer-events: none;`,
		});

const overlayId = overlays.add(elementId, {
			position: {
				top: 0,
				left: 0
			},
			html: overlayHtml
		});

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.bpmn.io/uploads/default/original/2X/b/b534893973385c2d302b38572464112e4adae002.png) [@system](https://forum.bpmn.io/u/system)\
**Post date:** [February 23, 2025, 10:01am UTC](https://forum.bpmn.io/t/adding-overlays-that-dont-prevent-mouse-events-being-captured-by-the-underlying-element/14375/3 "2025-02-23T10:01:58Z")

</div>

Closed on February 23, 2025, 10:01am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
