jQuery on() with custom data

Description

jQuery on() with custom data

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from w  w  w.j  a  v a 2  s.c  o  m
<script>
function handlerName(event) {
  document.getElementById("demo").innerHTML = event.data.msg;
}

$(document).ready(function(){
  $("p").on("click", {msg: "Hi!"}, handlerName)
});
</script>
</head>
<body>

<p id="demo"></p>
<p>Click me!</p>

</body>
</html>



PreviousNext

Related