Home >>jQuery Tutorial >jQuery trigger() Method

jQuery trigger() Method

jQuery trigger() Method

jQuery trigger() method in jQuery is used to triggers the specified event for the selected elements and the default behavior of an event (like form submission).

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

Parameter Values

Parameter Description
event It is a required parameter and used to specifies the event to trigger for the specified element.
param1,param2,... It is an optional parameter and used to attach additional parameters to pass on to the event handler.
Here is an Example of jQuery trigger() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").select(function(){
$("input").after(" Text marked!");
});
$(".btn1").click(function(){
$("input").trigger("select");
});
});
</script>
</head>
<body>
<input type="text" value="Hello Phptpoint"><br><br>
<button class="btn1">Click me to trigger the select event</button>
</body>
</html>

Output: