Posted By

1man on 04/27/11


Tagged

event trigger


Versions (?)

Check to see if function triggered by an event


 / Published in: jQuery
 

URL: http://jqfundamentals.com/book/index.html

Rather that using $(element).trigger('click'), check to see if execute has come from an element rather than directly.

  1. var foo = function(e) {
  2. if (e) {
  3. console.log(e);
  4. } else {
  5. console.log('this didn\'t come from an event!');
  6. }
  7. };
  8.  
  9.  
  10. $('p').click(foo);
  11.  
  12. foo(); // instead of $('p').trigger('click')

Report this snippet  

You need to login to post a comment.