How to check if TR TD contains a specific CSS class with jquery?

I know that you can use .find to search for td:contains('text') , but if I have tr, say 3 td, and one of td can have class="specialclass someotherclass" (there could potentially be other classes in addition to a special class), how can I use jquery to check if TR contains TD code specialclass ?

+8
jquery css jquery-selectors
source share
2 answers

To select any tr with td.specialclass :

 $('tr:has(td.specialclass)') 

Or, if you have tr (represented by this ), and you just want to check if it has such a td :

 if ($(this).find('td.specialclass').length) 
+25
source share
 if ($("tr").has("td.specialclass").length > 0) { // has specialclass } 

or

 if ($("tr:has(td.specialclass)").length > 0) { // has specialclass } 
+7
source share

All Articles