Check to see if function triggered by an event


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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')

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.