How to write a jQuery selector with multiple :eq's in single expression?

后端 未结 2 1298
甜味超标
甜味超标 2021-01-03 22:55

I have a quick question. How do I write a jQuery selector expression with multiple :eq() selectors? I want to go down the DOM tree but every hope isn\'t uniform. Here is wha

相关标签:
2条回答
  • 2021-01-03 23:21

    Using an each loop - elegant and not repetitive:

    $.each([0, 1, 5], (_, n) => {
        $('div').eq(n);
    });
    

    Last I checked, this technique performs best:

    $('div').filter(':eq(0), :eq(1), :eq(5)');
    
    0 讨论(0)
  • 2021-01-03 23:24

    I believe that you could do the following and it should return all dom elements that match:

     $('div:eq(0), div:eq(1), div:eq(5)')
    

    You could then iterate over the results returned, hope this helps.

    0 讨论(0)
提交回复
热议问题