jQuery Events – Trigger vs TriggerHandler

Let’s start from the very beginning in jQuery. Somewhere in the beginning there are events and buttons. So, I will start from there, explaining how to Trigger events and what is the difference between trigger and triggerHandlerTrigger triggers the event completely and triggerHandler triggers the event, without loading any part of the browser (or the DOM). This is probably better seen than explained.

Imagine, that you have three buttons – Button 1, Button 2 and Button 3. They are good and nice buttons and as such, each one of them is assigned with “click” functions. Different click functions.

Button 1 is in a form and thus when it is submitted, it goes to the link in the action of the form.

Button 2 is simply triggering a click action for button 1, whenever it is clicked. It also goes to the link, specified.

Button 3 is something else. It is with triggerHandler to Button 1. Thus, it makes a small action in the site – updates the div on the bottom, but it does not go to the link in the form. It avoids it.trigger_vs_handler

And in order to make this article a little more interesting, I have added some links, which behave in a similar way. And yet very different! It seems that if I use the same logic for the links as for the buttons, they simply do not work. Even the second link, which is a trigger to the first link.

Confused? Maybe. But the code really explains it well and feel free to run it until you grasp the idea!

Here comes the code:

Available also in GitHub!

That is all, folks! 😀

About

VBA Developer

Tagged with: , , ,