Javascript jQuery-在单击的div中更改span的CSS

Javascript jQuery-在单击的div中更改span的CSS,javascript,jquery,html,css,expand,Javascript,Jquery,Html,Css,Expand,我有一张桌子: <table> <tr class="row"> <td> Click me! <span class="expand" style="display: none;">Hidden text</span> </td> </tr> <tr class="row"> <td> Click m

我有一张桌子:

<table>
  <tr class="row">
    <td>
        Click me! 
        <span class="expand" style="display: none;">Hidden text</span>
    </td>
  </tr>

  <tr class="row">
    <td>
        Click me! 
        <span class="expand" style="display: none;">Hidden text</span>
    </td>
  </tr>
</table>
我使用$(this),因为同一个类中有许多
span
,我只想在单击的行中扩展span

$(".row").click(function () {
    $(this).find("span.expand").show(); //Shows specific span for each row
});
注意:
是错误的,因为
是一个类。使用
.row

通过jQuery设置样式

$(".row").click(function () {
    $(this).find(".expand").css('color','red');
    //to show use
    $(this).find(".expand").show();
});

也读


这应该能帮你解决问题:

jQuery:

$('.row').click(function(){
    $(this).find('span').show();
});
*请注意,每一行都有一个“row”类,因此元素是“.row”而不是“#row”(它将引用“row”的ID)

使用此代码

$('.row').click(function(){      // row is class not id
     $(this).find('span').show();
});
如果要切换显示(隐藏时显示和显示时隐藏),请使用

$('.row').click(function(){      // row is class not id
     $(this).find('span').toggle();
});

在下面的答案中使用css方法。另外,类不应该是
“.row”
而不是
“#row”
?#row引用的是一个ID,而不是一个class@PatDobson纠正了泰让我知道的事,我没看到
$('.row').click(function(){      // row is class not id
     $(this).find('span').toggle();
});