The trigger( event, [data] ) method triggers an event on every matched element.
Triggered events aren't limited to browser-based events, you can also trigger custom events registered with bind.
Here is the simple syntax to use this method:
selector.trigger( event, [data] )
Here is the description of all the parameters used by this method:
event: An event object or type to trigger.
data : This is an optional parameters and represents additional data to pass as arguments (after the event object) to the event handler.
Following is a simple example a simple showing the usage of this method. Here you would trigger a click event on square TWO by clicking on square ONE:
<html> <head> <script type="text/javascript" src="../../js/jquery-2.2.0.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#div1").click( function () { $("#div2").trigger('click'); }); $("#div2").click( function () { alert( "Square TWO is clicked"); }); }); </script> <style> div{ margin:10px;padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <span>Click square ONE to see the Output:</span> <div id="div1" style="background-color:blue;">ONE</div> <div id="div2" style="background-color:blue;">TWO</div> </body> </html>
Your Query was successfully sent!