停止冒泡事件onclick

stop bubbling event onclick

我有以下

<p>haha</p>
<button class="btn btn-light" onclick="nextSibling.classList.toggle('d-none');">
  <i class="fa fa-ellipsis-h"></i>
</button>
<div class="prev-content d-none">
  <p>second reply from second account</p>
  <br>
  <button class="btn btn-light" onclick="nextSibling.classList.toggle('d-none');">
    <i class="fa fa-ellipsis-h"></i>
  </button>
  <div class="prev-content d-none">
    <p>reply from system</p>
  </div>
</div>

我只想通过单击按钮显示下一个同级 <div class="prev-content">,但是有一些奇怪的行为。它显示所有 div 或隐藏所有 div。我觉得是冒泡事件的原因。

我该如何解决?

const toggleNext = (ev) => {
  const EL = ev.currentTarget;
  const EL_next = EL.nextElementSibling;
  EL_next.classList.toggle("u-none");
};
const ELs_tog = document.querySelectorAll("[data-toggle-next]");
ELs_tog.forEach(EL => EL.addEventListener("click", toggleNext));
.u-none {display: none;}
<button type="button" data-toggle-next>TOGGLE</button>
<div class="u-none">
  <p>second reply from second account</p>
  <button type="button" data-toggle-next>TOGGLE</button>
  <div class="u-none">
    <p>reply from system</p>
  </div>
</div>

补充阅读: