Using jQuery to search for <td> content
I am trying to use jQuery to search for <td> with given content (text) inside. For instance:
http://sotkra.com/btol/index.php
From left to right, the 7th COLUMN, which reads "TIPO MONEDA", displays PESOS or DOLARES. I would like to be able to do the following:
Select
<td>with the text "DOLARES" or "PESOS" and add a class to them.Select
<td>with the text 'DOLARES' or 'PESOS' and add the class to the parent<tr>s.
For # 1, I tried with this:
$('td[innerHTML=Dolares]').addClass('highlight'); as well as
$('td[html=Dolares]').addClass('highlight'); None of them worked.
Looking at the jQuery selector link , I don't think $('td[innerHTML=Dolares]') and$('td[html=Dolares]') will work.
I can only think of iterating through all the TDs and checking the contents of $(tdselector).html() .
You can try contains("Dolares") , as tvanfosson suggested. This works for your case, as it is unlikely that you will have "xxDolaresxx" in other TDs.