Select td based on text

1

I have a table where I want to select the td's that contains certain text. I've tried options like:

console.log($("#minhaTabela").find("td[value='A']"));
console.log($("#minhaTabela").find("td[text='A']"));
console.log($("#minhaTabela").find("td[innerText='A']"));
console.log($("#minhaTabela").find("td[context='A']"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><tableid="minhatabela">
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
</table>

All of the above do not return anything. How can I do this?

    
asked by anonymous 13.04.2016 / 22:19

1 answer

3

Well, the id of the table was wrong in the code (in camelCase when in html it is in low case). CSS is not able to filter by content, [] is valid only for attributes.

But since you're using this within jQuery, you can use :contains()

console.log($("#minhatabela").find("td:contains('A')"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><tableid="minhatabela">
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
</table>
    
13.04.2016 / 22:29