views:

59

answers:

2

#exceptions is a html table. I try to run the code below, but it doesn't remove the table row.

$('#exceptions').find('tr').each(function(){
    var flag=false;
    var val = 'excalibur';
    $(this).find('td').each(function(){
        if($(this).text().toLowerCase() == val) 
            flag = true;
    });
    if(flag)
        $(this).parent().remove($(this));
});

What is the correct way to do it?

+1  A: 

Does flag ever turn true? Try alerting it. There's also a less complicated way of removing an element:

if(flag)
    $(this).remove();
MvanGeest
even `$(this).detach()` worked!!!
deostroll
A: 

Assuming the variable flag ever evaluates to true, I think you may just want to do...

$(this).remove();

instead of...

$(this).parent().remove($(this));
Ryan