I need to remove three rows of a table when a link in the first row is clicked.
The rows are created dynamically using jQuery and pre-pended to the table as below.
var ups='';
ups+='<tr data-file='+file_id+'>';
ups+='<td width="40%">'+gl_file_name1+'</td><td>'+gl_upload_date1+'</td>';
ups+='<td>'+gl_upload_desc+'</td>';
ups+='<td><a href="sym.php?doc_id='+file_id+'" class="view2_fl">VIEW FILE</a> | <a href="javascript:void(0);" data-file='+file_id+' data-job='+job_id+' class="del2_fl">DELETE</a></td></tr>';
ups+='<tr><td>'+priority+'</td><td>'+price+'</td><td>'+tender+'</td><td> </td></tr>';
ups+='<tr class="bottom-row"><td colspan="4">'+notes+'</td><tr>';
$(ups).prependTo('.app_table');
This is looped for as many times as there are 'files'.
When the DELETE link is pressed I need to delete all three rows. So far I have managed to delete the first row using the code below:
$(this).closest("tr").remove();
I have tried to use .next() but this did not seem to work.
Get the row with the link, and from there you can get the next rows and add to the jQuery object, and remove all three in one go:
var tr = $(this).closest("tr");
tr.add(tr.next()).add(tr.next().next()).remove();
By first getting all three rows you don't have the problem that you want to find a row that is next to a row that you have already removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With