html table - JQuery delete rows allow a maximum of totalrows-1 -


i have dynamic table add , delete functions in jquery:

i deleting rows using following:

$("#del").click(function(){     $("table tr input:checked").parents('tr').remove(); }); 

fiddle: fiddle

how can avoid deleting columns in same time. mean if user checked rows , click delete, should show alert message. should allow delete maximum of totalrows-1

you can use jquery's size() function count number of rows checked inputs , compare total number of rows.

$("#del").click(function(){     var checked = $("table tr input:checked").size();     var total = $("table tr").size();     if (checked < total) {         $("table tr input:checked").parents('tr').remove();     } else {         alert("you cannot delete rows!");     } }); 

see updated fiddle here.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -