Javascript examples for jQuery Method and Property:trigger
The trigger() method triggers the events for the selected elements.
$(selector).trigger(event,param1,param2,...);
Parameter | Require | Description |
---|---|---|
event | Required. | event to trigger. |
param1,param2,... | Optional. | Additional parameters to pass on to the event handler. |
The following code shows how to trigger the select event of an <input> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").select(function(){ $("input").after(" Select event triggered!"); });/*from w w w . j a v a 2s. c o m*/ $("button").click(function(){ $("input").triggerHandler("select"); }); }); </script> </head> <body> <input type="text" value="Hello World"><br><br> <button>Trigger the select event for the input field</button> </body> </html>