I have a form and need to append a field as many times as required. If the button CLICK TO ADD ANOTHER FIELD
is clicked the div
should be appended. After the first append (onload), the div
responses correctly but from the second one on, I am not getting the similar response from the div
. Here is my JSFiddle
If I click on the TEST BUTTON
, I get alert for the first div
but on adding another div
(by clicking the CLICK TO ADD ANOTHER FIELD
button) , the button (TEST) doesn't work anymore for the second div
onwards.
I tried clone()
to help this but unable solve this one. May be I am not using it correctly.
To replicate the issue please follow the steps::
- Click on the
CLICK TO ADD ANOTHER FIELD
button to adddiv
- Click on the
TEST
button on the seconddiv
onwards
Please take a look and suggest. Thanks in advance.
You have to use delegation like
$(document).on('click','.test',function(){