Home > Article > Web Front-end > How does jQuery get class_html/css_WEB-ITnose based on value
See clearly, the class selector is not required to obtain the value!
f5d188ed2c074f8b944552db028f98a1
41c19e52b8cb740ffbc8b05861ddc23eStudy hardfd273fcf5bcad3dfdad3c41bd81ad3e5
41d818ac9c9acb0d0f19ace66fbe7ef8Tiantianshangshangfd273fcf5bcad3dfdad3c41bd81ad3e5
...
f16b1740fad44fb09bfe928bcc527e08
a34de1251f0d9fe1e645927f19a896e8 is a loop display, and the class of a34de1251f0d9fe1e645927f19a896e8 is a loop Numbered, now I know that the value of a certain a34de1251f0d9fe1e645927f19a896e8 is 'study hard', how can I get class ='1'
JS, Jquery will do
$.each($('tr td'),function(){ if($(this).text()=="天天向上") { alert($(this).attr("class")) }})
$.each($('tr td'),function(){ if($(this).text()=="天天向上") { alert($(this).attr("class")) }})
<table> <tr> <td class="2">天天向上</td> <td class="1">好好学习</td> </tr></table><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript">alert($("td:contains('好好学习')").attr("class"));</script>
<table> <tr> <td class="2">天天向上</td> <td class="1">好好学习</td> </tr></table><script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script> <script type="text/javascript">alert($("td:contains('好好学习')").attr("class"));</script>