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

后端 未结 2 1304
甜味超标
甜味超标 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)');
    

提交回复
热议问题