I am trying to use jQuery to find <td>
s with given content (text) inside. For example:
http://sotkra.com/btol/index.php
From left to right, the 7th COLUMN that reads 'TIPO MONEDA' displays either PESOS or DOLARES. I'd like to be able to do the following:
Select <td>
s with the text 'DOLARES' or 'PESOS' and add a class to them.
Select <td>
s with the text 'DOLARES' or 'PESOS' and add a class to their parent <tr>
s.
For #1, I tried with this:
$('td[innerHTML=Dolares]').addClass('highlight');
and also
$('td[html=Dolares]').addClass('highlight');
Neither of which worked.
You want to use :contains
.
$('td:contains("Dolares")').addClass('highlight');
for the parent
$('td:contains("Dolares")').parent().addClass('highlight');
Looking at the jQuery selector reference, I don't think$('td[innerHTML=Dolares]')
and$('td[html=Dolares]')
is going to work.
I can only think of iterating through all the TDs and check the $(tdselector).html()
content.
You can try contains("Dolares")
as suggested by tvanfosson though. It works for your case as it's highly unlikely you will have "xxDolaresxx" in other TDs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With