$(selector).trigger(event,param1,param2,...)
<!DOCTYPE html>
<html>
<head>
<title> jQuery trigger() method </title>
<script src="/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
#p2 {
border: 2px solid red;
width: 60px;
text-align: center;
}
</style>
<script>
$(document).ready(function(){
$("p").click(function(){
$("#tf").trigger("select");
});
$("#tf").select(function(){
$("#tf").css({"backgroundColor": "yellow", "fontSize": "25px"});
$("body").css({"backgroundColor": "lightgreen", "fontSize": "25px"});
});
});
</script>
</head>
<body>
<h4> This is an example of using the jQuery trigger() method </h4>
<input id = "tf" type = "text" value = "Text here...">
<br>
<p id = "p1"> Click the following text to see the effect. </p>
<p id = "p2"> Click me </p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
#p2 {
border: 2px solid red;
width: 60px;
text-align: center;
}
</style>
<script>
$(document).ready(function(){
$("#p2").click(function () {
$("#p2").bind("custom", function(event, id, name, salary){
alert("Employee ID = " + id + "\nName = " + name + "\nSalary = " + salary);
});
$("#p2").trigger("custom", ["E01", "John", "30,000"]);
});
});
</script>
</head>
<body>
<h4> This is an example of using the jQuery trigger() method </h4>
<p id = "p1"> Click the following text to see the effect. </p>
<p id = "p2"> Click me </p>
</body>
</html>