Jquery Manually Invoke Event Handlers
Learn to use jQuery to manually invoke Event handlers
jQuery Events: Manually Invoking Event Handlers
jQuery provides a set of methods to manually invoke event handling function.
Table : Methods to manually invoke Event Handlers
|trigger(eventType)||To trigger the handler function for the specified event types on all of the elements in a jQuery object.|
|trigger(Event)||To trigger the handler function for the specified event on all of the event on all of the elements in a jQuery object.|
|triggerHandler(eventType)||To trigger the handler function on the first element in the jQuery object, without performing the default action or bubbling the event.|
jQuery Events : Triggering Event Handlers Manually
The jQuery method of trigger() is used to manually invoke the event handlers.
The trigger() method executes the handlers in the same order as they would be executed if the events were triggered naturally.
Example: Triggering Event Handlers ManuallyGive it a TRY! » Note: It returns a jQuery Object, which can be used for chaining purposes
Manually triggering an Event Handler using an Event Object
A jQuery Event Object can also be used to trigger other element's Event Handlers
Example: Manually triggering an Event Handler Event ObjectGive it a TRY! » Note:If no class names are specified in the parameter, all classes will be removed.
jQuery Events : Using the triggerHandler() Method
The jQuery method of triggerHandler() `is used to invoke the handler function without performing the event's default action or allowing the event to bubble up the DOM.
But unlike the trigger method, the triggerHandler() method invokes the handler function only on the first element in jQuery Object.