trigger

UK[ˈtrɪgə(r)] US[ˈtrɪɡɚ]

n. (gun) trigger; starting device, trigger; triggering other events One thing; [Electronics] trigger, trigger electrical appliance

vt. trigger, trigger; pull the trigger of...; launch or cause explosion (weapons or explosive ammunition)

jquery trigger() method syntax

Function: trigger() method triggers the specified event type of the selected element.

Trigger event: Specifies the event to be triggered by the selected element.

Syntax: $(selector).trigger(event,[param1,param2,...])

Parameters:

ParametersDescription
event Required. Specifies the event to be triggered by the specified element. It is possible to make custom events (attached using the bind() function), or any standard events.
[param1,param2,...]Optional. Additional parameters passed to the event handler. The extra parameters are especially useful for custom events.

Use the Event object to trigger events: Specify the event to be triggered by the selected element using the event object.

Syntax: $(selector).trigger(eventObj)

Parameters:

ParameterDescription
eventObj Required. Specifies a function to run when an event occurs.

jquery trigger() method example

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").select(function(){
    $("input").after("文本被选中!");
  });
  $("button").click(function(){
    $("input").trigger("select");
  });
});
</script>
</head>
<body>
<input type="text" name="FirstName" value="Hello World" />
<br />
<button>激活 input 域的 select 事件</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance