How to detect if a click event was triggered by the user or programmatically

I often set up click handlers, then trigger it programmatically to set its default state (say an option click handler, where the first option is selected by default). This is a good pattern because you don’t end up with maintaining state via template and JS separately.

It’s also very common to want the programmatic click to happen very quietly, for example without scrolling the user down whereas a user click _should_ scroll the user down.

You simply need to check for the value of `event.originalEvent`.

if ev.originalEvent
console.log "This is a user event!"



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s