D
D
DeeUs2018-03-13 10:08:56
JavaScript
DeeUs, 2018-03-13 10:08:56

Why doesn't each() see new table rows?

Hello!
Using append() I add rows to the table, after which the maximum value in the column is searched

maximum value search code (spoiler)

var cv = 0, max = 0;                                    
$('.border_options table tbody tr.option_item').each(function(){                                       
     cv = parseInt($('td.sort input', this).val());
     max = max < cv ? cv : max;
});
$('#finp_add_sort').val(max+1); // это поле формы для добавления новой строки


but for some reason the script searches for the table that was formed at the very beginning (does not take into account new rows of the table when searching)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lone Ice, 2018-03-13
@daemonhk

Because they are not in the DOM when you add them dynamically. The easiest way to get them is to call the function after adding them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question