M.Gooda M.Gooda - 6 months ago 3x
Javascript Question

how to loop after specified number of rows in table

I have a

<table id="table">

A user can add rows in this table when clicking
<button id="new">

A user can save by clicking
<button id="save">

If a user adds more than 5 rows without saving data, then they should get an alert to save. This alert should be repeated in each 5 new rows.

I've tried this :

var count = $('#table tbody').children('tr').length;
if (count > 4) {
var y = confirm("you should to save your data!");
if (y == true){
else {



Instead of using the > operator, you should use the modulo operator.

So change your if to this:

if (count > 0 && count % 5 == 0) {