The code should print the id of the selected div but it does not. I did not find the error. Thanks for help.
HTML
Ok, I think I understand what you are missing. You are trying to log the ID
after adding a row using add_row
function,
.form_row
is added dynamically to the DOM. So when executing $('.form_row').click(
, there is no .form_row
to bind the handler. The below way of using .on
method binds the handler to #form_area
and executes the handler only when the click event is from .form_row
$('#form_area').on('click', '.form_row', function () {
console.log(this.id);
});
$('#form_area div')
selects the div
inside the div #form_area
which doesn't have an ID
Below comment in html shows which div is selected,