trigger() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:trigger

Description

The trigger() method triggers the events for the selected elements.

Syntax

$(selector).trigger(event,param1,param2,...);
Parameter RequireDescription
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 . j a v a 2s. 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