triggerHandler() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:triggerHandler

Description

The triggerHandler() method triggers the event for the selected element.

Syntax

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:

Demo Code

ResultView the demo in separate window

<!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 .  jav a 2 s  .  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>

Related Tutorials