I have some paragraphs in my html as an example, and when I click on it, the JQuery click activates correctly and executes de function. However, I have a button that adds new paragraphs to de body but the new ones do nothing on click and I don't know why:
My html body
<h1> Test </h1>
<input type="text" id="newP" value="New paragraph">
<button id="add"> Add </button>
<p> Paragraph 1 </p>
<p> Paragraph 2 </p>
My js file
$(document).ready(function(){
$("p").click(function(){
console.log("Hello");
this.remove();
});
$("#add").click(function(){
$("#add").after("<p> " + $("#newP").val() + "</p>");
});
});
The 2 example paragraphs delete correctly and shows "Hello" but de new ones don't. I want to do something more complicated than just deleting them so I need to know why the function isn't working for them. (I must use JQuery)