var op = $("#output"); // if you just do this then any new p tags added wont have the click event //$("p").click(function() { // op.append("p clicked <br/>"); //}); // with on even the newer ones will also have the click event $("body").on("click", "p", function(e) { op.append("p clicked <br/>"); }); $("#btn1").click(function() { $("#div1").append("<p>something</p>"); });
<div id="div1"> <p id="p1">some paragraph 1</p> <p id="p2">some paragraph 2</p> </div> <br/><br/> <input type="button" id="btn1" value="Add"/> <br/><br/> <div id="output"></div>
#btn1{margin:2px; padding:10px} p{margin:5px; padding:5px; border:red 1px solid;}