Rob P
Rob P

Reputation: 21

Selecting all TRs where a specific TD contains specific text

Trying to select all rows where a cell in a specific location contains a specific value.

example:

<table>
  <tr>
    <td>1</td>
    <td>MO</td>
    <td>MO Williams</td>
  </tr>
  <tr>
    <td>2</td>
    <td>PG</td>
    <td>MO Williams</td>
  </tr>
</table>

I want to ONLY select the rows where the 2nd contains MO.

I've tried this:

     $('tr:has(td:eq(1):contains(MO))') 

but that doesn't work. Thank you.

Upvotes: 2

Views: 1707

Answers (1)

hunter
hunter

Reputation: 63532

Selects all td elements:

$("tr").find("td:eq(1):contains('MO')")

working example: http://jsfiddle.net/hunter/jBbS7/


Selects all tr elements:

$("tr").find("td:eq(1):contains('MO')").parents("tr");

working example: http://jsfiddle.net/hunter/jBbS7/4/

Upvotes: 4

Related Questions