views:

98

answers:

1

I have some html which I would like to manipulate. Its structure is as follows:

<tr>
    <td>
     <nobr>TEXT_TO_LOOK_FOR</nobr>
    </td>
</tr>

I've written a function here which hides the row containing this text, but I'm just wondering if anyone can clean it up. I feel like it is probably making jquery do more work than it needs to.

I know I could search for a row which contains the text, but I want the function to be robust, so that it does not hide rows if the text is found elsewhere.

function hideRowContainingText(strText)
{
    var rowMatches = $('tbody tr td nobr:contains(' + '"' + strText + '"' + ')');
    rowMatches.eq(0).parent().parent().parent().css("display", "none");
}

Thanks for any help!

+1  A: 

I think this is equivalent:

function hideRowContainingText( strText )
{
    $('td nobr:contains("' + strText + '")').eq(0).closest('tr').hide();
}
tvanfosson
Thank you. Exactly what I was looking for.
vwfreak034