jQuery trigger() with custom event

Description

jQuery trigger() with custom event

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>// w w  w.  j  av a  2s .  c  om
<script>
$(document).ready(function(){
  $("p").click(function(){
    $("p").on("myPara", function(event, param1, param2, param3){
      document.getElementById("demo").innerHTML = param1 + "\n" + param2 + "\n" + param3;
    });
  $("p").trigger("myPara", ['A', 'B', 'C']);
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<p>Click to alert additional parameters.</p>

</body>
</html>



PreviousNext

Related