xxx

Why can't I select <td> using its class and data attributes in jQuery?

<table> <tr> <td class="ok" data-test="12-12 00">xxx</td> <td class="ok" data-test="13-12 00">xxx</td> <td class="ok" data-test="14-12 00">xxx</td> <td class="ok" data-test="15-12 00">xxx</td> </tr> </table> 

I would like to get <td> where data-test = "14-12 00" . Here is my code:

 alert($('td .ok[data-test="14-12 00"]').text());​ 

Why is this not working?

http://jsfiddle.net/LqD5h/

+4
source share
2 answers

Try:

 alert($('td.ok[data-test="14-12 00"]').text());​ 

(Note that there is no space between td and .ok ).

Initially, you tried to select all elements named class ok , which are descendants of a td and carry a specific data-test value.

+10
source

What about another way to hide this cat?

 alert($('tr .ok[data-test="14-12 00"]').text());​ 

Note that td changed to tr . tr

+2
source

Source: https://habr.com/ru/post/1444094/


All Articles