Jquery .remove()

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');
}

Stupid mistake on my part…I fixed it :expressionless:

           //compare changes buttons
			$('body').on('click', '.compare-change', function() {
			//$('.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();
						$(this).text('Compare'); 
						exit();
						//alert('hellow');
					}
					  
				}
				
				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 () {
					
				});
			
				
				//console.debug(callerCellRow.prev().html());
			});
Sponsor our Newsletter | Privacy Policy | Terms of Service