David David - 1 year ago 69
jQuery Question

jQuery - find table row containing table cell containing specific text

I need to get a

tr
element which contains a
td
element which contains specific text. The
td
will contain that text and only that text (so I need
text = 'foo'
not
text contains 'foo'
logic).

So I need the equivalent of the following 'pseudo jQuery':

var tableRow = $(table td[text = 'foo']).parent('tr');


Can anyone provide the correct syntax?

Answer Source

You can use filter() to do that:

var tableRow = $("td").filter(function() {
    return $(this).text() == "foo";
}).closest("tr");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download