# Triggering a Modal from a Link?

**URL:** <https://forums.realmacsoftware.com/t/triggering-a-modal-from-a-link/48453>\
**Category:** Elements\
**Created:** [June 28, 2025, 7:44pm UTC](https://forums.realmacsoftware.com/t/triggering-a-modal-from-a-link/48453 "2025-06-28T19:44:50Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![ben](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/ben/32/28488_2.png) [@ben](https://forums.realmacsoftware.com/u/ben)\
**Post date:** [July 5, 2025, 6:41am UTC](https://forums.realmacsoftware.com/t/triggering-a-modal-from-a-link/48453/12 "2025-07-05T06:41:44Z")

</div>

Yes, you **can** trigger a modal from a link or button elsewhere on the page, but it does require some custom code.

* * *

⚠ **Important Note:** This technique relies on the internal structure of the Modal component and may break in the future if we update how modals work. **Use with caution**.

* * *

### Step 1: Find the Modal ID

Before you begin, locate the **ID** of the Modal you want to open. You’ll need to use that in the code examples below.

 ![CleanShot 2025-07-05 at 08.34.45@2x](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/3/6/361149a8ebf9ecf57fc5f615a7b430767c9b26bc.jpeg)

### Step 2: Trigger the Modal

You can trigger the modal by dispatching a custom event named open-modal on the window object. There are two approaches:

**1. Native Javascript**

```html
<button id="openModalBtn">Open Modal</button>

<script>
  document.getElementById('openModalBtn').addEventListener('click', function () {
    const event = new CustomEvent('open-modal', {
      detail: { id: 'THE_MODAL_ID' }
    });

    window.dispatchEvent(event);
  });
</script>

```

**2. Using Alpine**

```html
<div
  x-data
  @click="$dispatch('open-modal', { id: 'THE_MODAL_ID' }">
    Open Modal
</div>

```

You can [download an example project using this technique here](elementsapp://downloadDocument/1Yj0r1WWadke). Enjoy! 😃

---

_[View the full topic](https://forums.realmacsoftware.com/t/triggering-a-modal-from-a-link/48453)._
