如何在div下选择第二个表结构?

时间:2013-08-08 22:19:49

标签: javascript jquery html jquery-selectors

我想在table下选择每一秒div

所以我的HTML就像

<div class ='tableDiv'>
  <table class='table'>
    ....
  </table>

  <table class='table'>
    ....
  </table>

</div>

...other stuff...

<div class ='tableDiv'>
  <table class='table'>
    ....
  </table>

  <table class='table'>
    ....
  </table>
</div>

other stuff

<div class ='anotherTableDiv'>
  <table class='table'>
    ....
  </table>

  <table class='table'>
    ....
  </table>
</div>

我正在尝试选择“tableDiv”div下的每个第二个表格。

我试过了。

$('.tableDiv table:nth-child(even));

但它不起作用。我无法真正更改类名或添加ID,因此有点困难。任何人都可以给我一个暗示吗?非常感谢!

2 个答案:

答案 0 :(得分:2)

使用jQuery的:even选择器。

$('.tableDiv table:even')

答案 1 :(得分:2)

确保关闭引号。除此之外,你开始的很好。