jQuery find an element by its index

后端 未结 7 1850
灰色年华
灰色年华 2020-12-21 16:18

If I have a selection

item 1
item 2
item 3
7条回答
  •  萌比男神i
    2020-12-21 16:49

    Use eq() method.

    $("#container > div").eq(1)
    

    You can even use :eq(1) pseudo selector.

    $("#container > div:eq(1)")
    

    .eq(index) reduces the set of matched elements to the one at the specified index.

    :eq(index) selects the element at index n within the matched set.

提交回复
热议问题