title: Bootstrap collapse - how to add additional click behavior that depends on the state of collapse or not
body: <p>I have a button that controls the expansion/collapse of a collapsible div.  But I want to add additional functionality on click that depends on whether the div is expanding or collapsing.  I wrote this code:</p>
  
  <pre><code>    buttonElement.click(function() {
        if ($(this).hasClass("collapsed")) {
          // do the thing I want to do when expanding
        } else {
          // do the thing I want to do when collapsing
        }
      })
  </code></pre>
  
  <p>This works, but I'm wondering if it's robust.  It assumes that my click function runs before the data-toggle changes the class, and I'm not sure if it's appropriate to assume this.</p>