I’m trying to remove a the row below the row which the function is called within; if the the next row has a class of “compare-results”. My code works fine except for the remove(). It alerts within the code block but won’t delete the row…
//compare changes buttons
$('.compare-change', this).click(function() {
var buttonText = $(this).text();
if (buttonText == 'Compare') {
$(this).text('Hide');
} else {
$resultsRow = $(this).closest('tr').next();
if ($resultsRow.attr('class') == 'compare-results') {
$resultsRow.remove();
alert('hellow');
}
$(this).text('Compare');
}
var callerCellIndex = $(this).prevAll().length; //current cell index
var callerCellRow = $(this).closest('tr'); //current row of caller cell
var callerPrevRow = callerCellRow.prev(); //row before caller cell
var resultsRowHTML = '<tr class="compare-results"><th scope="row"></th><td>test</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
// create new row to display results in
callerCellRow.after(resultsRowHTML);
//loop through each cell in callerCellRow
$(callerCellRow.children('td:not(:last)'), this).each(function () {
});
});
This is the problem area:
if ($resultsRow.attr('class') == 'compare-results') {
$resultsRow.remove();
alert('hellow');
}