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
Post a Comment