vwfreak
vwfreak

Reputation: 368

jquery contains help

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!

Upvotes: 1

Views: 1504

Answers (1)

tvanfosson
tvanfosson

Reputation: 532435

I think this is equivalent:

function hideRowContainingText( strText )
{
    $('td nobr:contains("' + strText + '")').eq(0).closest('tr').hide();
}

Upvotes: 1

Related Questions