I have a select input in which the options are 1-6. Depending on the value of that, the same number of inputs are appended to an empty div with unique Id's as such:
$('#no_of_children').change(function() {
let inputContainer = $('#children_inputs');
console.log(inputContainer);
inputContainer.empty();
let num = $(this).val();
console.log(num);
for(let i = 1; i<=num; i++) {
inputContainer.append("<div class='form-group'><label>Child "+i+". Age: <span id='span_child"+i+"' class='font-weight-bold text-danger'></span></label><input class='form-control' type='date' name='child' id='child"+i+"'></div>");
}
});
What I expect to happen afterwards is to be able to use $('#child(n)')
to get the the input (n being whatever number 1-6). When I inspect the element I see that the inputs are there with the correct ID, but the jQuery selector cannot find it.
I have also tried:
$('#child1').on('change', function() {
console.log("changed");
})
which was recommended when I researched this problem but it does not work for me.