title: Simulate native click
body: <p>I need to trigger the click event on a link and then, if none of the listeners prevented the default, change the location. </p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>var $el = $('a#my_special_link');
  var onClick = $el.attr('onclick');
  
  // Hack to capture the event object
  var ev_reference;
  var ev_capture = function(ev) { ev_reference = ev; }
  $el.bind('click', ev_capture);
  
  // Don't leave out the onClick handler
  if ( typeof onClick == 'function' )
      $el.bind('click', onClick);
  
  $el.trigger('click');
  
  // Clean up
  $el.unbind('click', ev_capture);
  if ( typeof onClick == 'function' )
      $el.unbind('click', onClick);
  
  // Redirect if necessary
  if ( ! ev_reference.isDefaultPrevented() )
    window.location = $el.attr('href');
  </code></pre>
  
  <p>Any suggestions for improvement are welcome.</p>
  
  <p><strong>PS:</strong> Yes, it's just how a regular link would work, except you can do some other processing in between.</p>
  
  <p><strong>PPS:</strong> No, just doing $el.trigger('click'); will <em>not</em> change the location.</p>