2

I'm using Bootstrap-Native, I want to detect when a modal is closed, is there a way to do this with plain javascript?

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

I tried:

document.getElementById("exampleModal").addEventListener("transitionend", console.log("closed"));

But event doesn't fire.

Artemis
  • 589
  • 1
  • 6
  • 19

1 Answers1

0

This question can be found repeated here: Bind a function to Twitter Bootstrap Modal Close.

See the answer:

var myModalEl = document.getElementById('myModalID');
myModalEl.addEventListener('hidden.bs.modal', function (event) {
    // do something...
});
Andre
  • 562
  • 2
  • 7
  • 18