Javascript examples for jQuery Method and Property:on
Create custom event handler, trigger custom event
<!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").on("myOwnEvent", function(event, showName){ $(this).text(showName + " is me!").show(); });/* ww w . j av a 2 s .c o m*/ $("button").click(function(){ $("p").trigger("myOwnEvent", ["java2s.com"]); }); }); </script> </head> <body> <button>Trigger custom event</button> <p>Click the button to attach a customized event on this p element.</p> </body> </html>