I am little confused with this problem. I am trying to create a dynamic form, in which the used can make as many descriptions, checkboxes and number inputs and he wants. I am just creating a simple dynamic formular with jQuery, and so far I can create elements that they delete themselves (when the user click on remove the field) and I can add more elements in the form. Code as follows:
<!-- THE FIELD THAT I APPEND IS A COPY OF THIS ITEM -->
<div class="container-field-form" id="description-field">
<div class="container-field-form__img remove">
<img src="/static/svg/problem.svg" class="icon-to-do-form img-zoom-min " id="deleteButton">
</div>
<div class="container-field-form__field form-field">
<textarea onchange="this.value = capitalizeFirstLetter(this.value)" class="form-control form-field" name="description" id="description" rows="3" placeholder="Enter the description"></textarea>
</div>
</div>
<!-- FROM HERE I APPEND AND ONLY APPEARS ONE AT THE BEGGGINING -->
<div class="container-field-form" id="description-field">
<div class="container-field-form__img" id="add-description">
<img src="/static/svg/add-component.svg" class="icon-to-do-form img-zoom-min " id="deleteButton">
</div>
<div class="container-field-form__field form-field">
<textarea onchange="this.value = capitalizeFirstLetter(this.value)" class="form-control form-field" name="description" id="description" rows="3" placeholder="Enter the description"></textarea>
</div>
</div>
The problem that I have here, is that the items that I hardcoded in the HTML, they answer correctly (remove when they need to be removed or duplicate any camp), but with the new items that I add to the HTML, they do not answer to the listener (and it is a exact copy from the html, in the html hardcoded will work with any number, with the html inserted with jQuery no.
Here I give you the jQuery code, that just prepend a copy of the field of the HTML (working with no problem) and that removes the field when we click to remove (removes the current field and works but only in the hardcoded html)
$("#add-description").click(function() {
$("#description-fields").prepend('<div class="container-field-form" id="description-field"><div class="container-field-form__img remove"><img src="/static/svg/problem.svg" class="icon-to-do-form img-zoom-min " id="deleteButton"></div><div class="container-field-form__field form-field"><textarea onchange="this.value = capitalizeFirstLetter(this.value)" class="form-control form-field" name="description" id="description" rows="3" placeholder="Enter the description"></textarea></div></div>')
});
$(".remove").click(function() {
$(this).parent().remove();
});
Am I missing something? Thanks in advance