{"id":8201,"date":"2010-12-25T08:29:05","date_gmt":"2010-12-25T15:29:05","guid":{"rendered":"http:\/\/css-tricks.com\/"},"modified":"2010-12-25T08:29:05","modified_gmt":"2010-12-25T15:29:05","slug":"check-if-event-was-triggered-or-native","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/jquery\/check-if-event-was-triggered-or-native\/","title":{"rendered":"Check if Event was Triggered or Native"},"content":{"rendered":"
$('button').click(function(event, wasTriggered) {\r\n if (wasTriggered) {\r\n alert('triggered in code');\r\n } else {\r\n alert('triggered by mouse');\r\n }\r\n});\r\n\r\n$('button').trigger('click', true);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"$(‘button’).click(function(event, wasTriggered) { if (wasTriggered) { alert(‘triggered in code’); } else { alert(‘triggered by mouse’); } }); $(‘button’).trigger(‘click’, true);<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3245,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":151204,"url":"https:\/\/css-tricks.com\/lodge\/learn-jquery\/14-custom-events\/","url_meta":{"origin":8201,"position":0},"title":"#14: Custom Events","date":"September 27, 2013","format":false,"excerpt":"Since we just talked about events, now is a good time to mention custom events. All the events that we've talked about so far are \"real\" events so to speak. Events that originate in the DOM based on real things that happen, like a click or key press. These events\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":21048,"url":"https:\/\/css-tricks.com\/video-screencasts\/123-if-it-moves-when-you-click-make-something-stick\/","url_meta":{"origin":8201,"position":1},"title":"#123: If it Moves When You Click, Make Something Stick","date":"April 9, 2013","format":false,"excerpt":"The buttons on CSS-Tricks, at the time of this video, have a faux 3D effect. They look like a blue brick you are looking at from above at an angle. When you press down on them, their :active state is triggered (like all links\/buttons\/inputs) and the CSS moves them down\u2026","rel":"","context":"With 14 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":345532,"url":"https:\/\/css-tricks.com\/almanac\/selectors\/b\/backdrop\/","url_meta":{"origin":8201,"position":2},"title":"::backdrop","date":"August 3, 2021","format":false,"excerpt":"The ::backdrop CSS pseudo-element creates a backdrop that covers the entire viewport and is rendered immediately below a