Trigger custom event and pass in custom data - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:trigger

Description

Trigger custom event and pass in custom data

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(){
    $("p").click(function(){
        $("p").on("myPara", function(event, param1, param2, param3){
        console.log(param1 + "\n" + param2 + "\n" + param3);
    });//ww  w  .  j  av  a  2 s.c  o m
    $("p").trigger("myPara", ['A', 'V', 'C']);
    });
});
</script>
</head>
<body>

<p>Click to trigger event with additional parameters.</p>

</body>
</html>

Related Tutorials