How to determine if a bootstrap collapse is opening or closing? How to determine if a bootstrap collapse is opening or closing? jquery jquery

How to determine if a bootstrap collapse is opening or closing?


Bootstrap uses the aria-expanded attribute to show true or false if the region is collapsed or not.

var isExpanded = $(collapsableRegion).attr("aria-expanded");


Try:

$('#collapseDiv').on('shown.bs.collapse', function () {   console.log("Opened")});$('#collapseDiv').on('hidden.bs.collapse', function () {   console.log("Closed")});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/><div>  <a id=@space.EventId class="register-student-link" data-toggle="collapse" href="#collapseDiv" aria-expanded="false" aria-controls="collapseExample">Register Student</a></div><div class="collapse" id="collapseDiv">This is the collapsible content!</div>