Norbert
Norbert

Reputation: 2771

jQuery: Using Variables in Selectors

Every searches I made only included solutions for variables like this: $('#div'+ id)

I need to delete a row.

var row = $(this).parent().parent().parent().find('tr#' + id).html();

I'd like to use the "row" name instead of "$(this)...remove();"

Upvotes: 0

Views: 1125

Answers (3)

redsquare
redsquare

Reputation: 78667

use .closest, it is safer than all those chained parent calls in case you change the markup which will break the code.

var row = $(this).closest('tr');
row.remove()

Upvotes: 4

White Elephant
White Elephant

Reputation: 1381

Just populate the row var with a reference to the row.

var row = $(this).parent().parent().parent().find('tr#' + id);
var html = $(row).html();
$(row).remove();

Upvotes: 1

kon
kon

Reputation: 554

like

$('tr[name='+rowname+']').remove()

Upvotes: 6

Related Questions