removing and appending rows to tables
I have 4 tables on a page with similar structure. Differences are the table id's and the number of tds per row, two tables have 2 per row, the other two have 4. Basic structure is:
<table id="mytable"> <tbody> <tr id="tempRowID"> <td class="delete"> <img src="myImage.png" /> </td> </tr> </tbody> </table>
And the query is:
- $(document).on('click', 'table td', function () {
- var blankRowShort = "<tr id='tempRowID'><td colspan = 2>No Information entered.</td></tr>";
- var blankRowLong = "<tr id='tempRowID'><td colspan = 4>No Information entered.</td></tr>";
- var currentTable = $(this).closest('table').attr("id");
- $(this).parent().remove();
- if ((currentTable == "IDTable") || (currentTable == "aliasTable")) {
- $(this).parent().append(blankRowLong);
- }
- else {
- $(this).parent().append(blankRowShort);
- }
- });
So the function works great, until the if statement. Line 8 removes the row but then I need to add one of the generic 'no info' rows depending on which table and nothing I try seems to work. Some other things I've tried are:
- $(this).closest('table').append(blankRowShort);
- $('"#' + currentTable + '"').parent().append(blankRowLong);
Some ideas would be great, thank you.