title: jQuery trigger custom event synchronously?
body: <p>I am using the jQuery trigger method to call an event... but it behaves inconsistently. Sometimes it call the event, sometimes it does not.</p>
  <pre><code>&lt;a href=&quot;#&quot; onclick=&quot;
      $(this).trigger('custom-event');
      window.location.href = 'url';
      return false;
  &quot;&gt;text&lt;/a&gt;
  </code></pre>
  <p>The <code>custom-event</code> has lots of listeners added to it.
  It is as if the trigger method is not synchronous, allowing the <code>window.location.href</code> be changed before executing the events. And when window.location.href is changed a navigation occurs, interrupting everything.</p>
  <p>How can I trigger events synchronously?</p>
  <p>Using jQuery 1.8.1.</p>
  <p><strong>EDIT</strong></p>
  <p>I have found that the event, when called has a stack trace like this:</p>
  <ol>
  <li>jQuery.fx.tick (jquery-1.8.1.js:9021)</li>
  <li>tick (jquery-1.8.1.js:8499)</li>
  <li>jQuery.Callbacks.self.fireWith (jquery-1.8.1.js:1082)</li>
  <li>jQuery.Callbacks.fire (jquery-1.8.1.js:974)</li>
  <li>jQuery.speed.opt.complete (jquery-1.8.1.js:8991)</li>
  <li>$.customEvent (myfile.js:28)</li>
  </ol>
  <p><strike>This proves that jQuery <code>trigger</code> method is asynchronous.</strike> (I was wrong... this only proves that the event I was calling, had an animation inside it, and was calling the expected function inside the callback after the animation)</p>