title: Queue up a function after click events
body: <p>I have a problem with queuing up events in jQuery. I have an elevator project that allows the user to click on buttons, and then lights go on and then numbers change. That works fine, except when they punch a number again before it reaches the floor picked the first time. I want it to get to the floor first picked before it goes to the second clicked floor (or third, or fourth, etc.). I've done some stuff with <code>.promise</code>, when done, etc. and none of it seems to work.</p>
  <p>I am using <code>.click</code> which appears to be the issue, because it fires the function regardless of where it is currently. Trouble is that I can't seem to find any alternative and it needs to finish current operation first before moving on to any other floors.</p>
  <p>I hope I explained this well. If not please let me know. Perhaps there is another way entirely of doing it. Still learning this front end/jQuery stuff.</p>
  <pre><code>$( &quot;.button&quot; ).click(function(event) {      
      // doing stuff here....
      $( runMainscript() ).promise().done(function() {
          runMainscript(buttonclicked, floorQ);
      });
  
  });
  
  function runMainscript(buttonclicked,floorQ) {
      //doing stuff here
  }
  </code></pre>
  <p>BTW, here is a timer for 2 seconds on each floor.</p>
  <p>JSfiddle: <a href="http://jsfiddle.net/ak25Lxab/1/" rel="nofollow noreferrer">http://jsfiddle.net/ak25Lxab/1/</a></p>
  <p>See how if you click on two buttons quickly, it jumps around?</p>