How do I select every pair of 2 sequential elements in jQuery?

前端 未结 5 2072
余生分开走
余生分开走 2020-12-20 20:50

Can anyone please help me to work out how to achieve the following? I have a set of divs of unknown size. Each div has a class of .feature. I need to run a jQuery script to

5条回答
  •  天命终不由人
    2020-12-20 21:06

    Let's jump to the assumption that you can fix the HTML to make it valid, and it looks like:

    You can then use a selector like:

    $("div:odd")
    

    or

    $("div:even")
    

    more like:

    $("div:even").children(':even');
    

    NOTE: 0 based index, so 2,4,etc (normal count) are ODD...

提交回复
热议问题