jQuery trigger() Method

Last Updated:

jQuery trigger() Method

The jQuery trigger() method execute all handlers and behaviors attached to the matched elements for the given event type.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery trigger() Method</h1> <button>Click Me</button> <button>Click Me</button> <script> $(document).ready(function(){ $("button").click(function(){ alert("Button was clicked"); }); $("button").trigger("click"); }); </script> </body> </html>

Syntax

$(selector).trigger(eventType, extraParameters);

Parameter Values

Value Type Explanation
eventType Required Specifies a string containing a JavaScript event type, such as click or submit.
extraParameters Optional Additional parameters to pass along to the event handler.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
trigger()YesYesYesYesYesYesYesYesYesYesYesYesYes

Share this Page

Meet the Author