How to select second table structure under a div?

2019-08-12 21:22发布

I am trying to select every second table under a div.

so my html is like

<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>

I am trying to select every second table under 'tableDiv' div.

I tried.

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

but it doesn't work. I can't really change class name or add an ID so it's a bit difficult. Can anyone gives me a hint for it? Thanks a lot!

2条回答
beautiful°
2楼-- · 2019-08-12 21:31

Use jQuery's :even selector.

$('.tableDiv table:even')
查看更多
3楼-- · 2019-08-12 21:57

Make sure you close your quote marks. What you started with is fine except for that.

查看更多
登录 后发表回答