css nth-child(2n+1) repaint css after filtering out list items

前端 未结 2 1971
广开言路
广开言路 2021-01-14 00:28

I have a list of 20+ items. The background-color changes using the :nth-child(2n+1) selector. (ie. even item black, odd item white). When I click a button to filter out spec

2条回答
  •  死守一世寂寞
    2021-01-14 01:26

    Nth-child can be counterintuitive when working with a filtered selection of a group.

    Use .each() to get around its limitations:

    var count = 1;
    $('#element tr:not(.isotope-hidden)').each(function(){
        if ( count++ % 2 == 1 ) $(this).css('background-color','white')
    })
    

提交回复
热议问题