HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery on() Method</h1> <button>Generate Paragraph</button> <script> $(document).ready(function(){ $(document).on("click", "p", function(){ alert("on() is triggered"); }); $("p").click(function(){ alert("click() is triggered"); }); $("button").click(function(){ $("body").append("<p>Click on this paragraph.</p>"); }); }); </script> <p><strong>Note</strong>: click event will not trigger for dynamically generated paragraph.</p> </body> </html>
OUTPUT
×

Save as Private