jQuery :first vs. .first()

前端 未结 4 1739
夕颜
夕颜 2020-11-29 01:12

The .first() method was added in jQuery 1.4.

The :first selector has been around since 1.0.

From the docs:

:first

4条回答
  •  难免孤独
    2020-11-29 02:09

    $('li').css('color', 'red').first().css('color', 'green'); would apply the filter after the collection already has been utilised.

    In most cases I would use the selector :first since it can be combined with so many other nice selectors, all in one sweep.

提交回复
热议问题