jQuery delegate()
with optional data
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*from www . jav a 2 s . c o m*/ <script> function handlerName(e){ document.getElementById("demo").innerHTML = e.data.msg; } $(document).ready(function(){ $("p").delegate({msg: "You just clicked me!"}, "click", handlerName) }); </script> </head> <body> <p id="demo"></p> <p>Click me!</p> </body> </html>