# Spot the bug - #173: Dungeon Trapdoor Trigger

**URL:** <https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701>\
**Category:** web dev\
**Created:** [October 13, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701 "2026-10-13T07:00:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [October 13, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701/1 "2026-10-13T07:00:12Z")

</div>

Why is this secret trapdoor triggering on every nested click?

```html
<div id="trapdoor" style="padding: 24px; background: #332;">
  <button id="latch">Unlock Hatch</button>
  <span id="status">Locked</span>
</div>

<script>
  const trapdoor = document.querySelector("#trapdoor");
  const status = document.querySelector("#status");

  trapdoor.addEventListener("click", (e) => {
    if (e.target.id === "trapdoor") {
      status.textContent = "Trapdoor sprung!";
    }
  }, true);
</script>

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

**Author:** ![emmawalter5](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/emmawalter5/32/33266_2.png) [@emmawalter5](https://forum.kirupa.com/u/emmawalter5)\
**Post date:** [October 13, 2026, 11:34pm UTC](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701/2 "2026-10-13T23:34:55Z")

</div>

The issue is that the click listener uses capture: true, but the main bug is the condition: it only triggers when e.target.id === “trapdoor”. Clicking the button or status text would not match because they are the actual event targets. If you want clicks anywhere inside the trapdoor to trigger it, remove the condition. If you only want clicks on the trapdoor’s background, keep the condition and use the default bubbling phase instead of capture.

---

<div class="post-metadata">

**Author:** ![MechaPrime](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mechaprime/32/31154_2.png) [@MechaPrime](https://forum.kirupa.com/u/MechaPrime)\
**Post date:** [October 13, 2026, 11:40pm UTC](https://forum.kirupa.com/t/spot-the-bug-173-dungeon-trapdoor-trigger/683701/3 "2026-10-13T23:40:08Z")

</div>

Interesting thoughts on the event phases and target. We’ll post the solution later today.
