by
82k 39
2
7
268k
11
Top 1% !
Popular
Pearl of Wisdom
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 4714th place
environmenthtml
Frameworkjquery
Languagejavascript
LicenseMIT_X11

Check if Event was Triggered or Native

You can easily add extra argument when triggering an event function programmatically in jquery.
This way you can recognize if the event was triggered by a real mouse click rather than a direct call to the .click() function.

As seen on http://css-tricks.com/snippets/jquery/check-if-event-was-triggered-or-native/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/294/Check-if-Event-was-Triggered-or-Native?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
$('button').click(function(event, wasTriggered) { if (wasTriggered) { alert('triggered in code'); } else { alert('triggered by mouse'); } }); $('button').trigger('click', true);
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus