Are jQuery's :first and :eq(0) selectors functionally equivalent?

前端 未结 3 1721
礼貌的吻别
礼貌的吻别 2020-12-17 14:27

I\'m not sure whether to use :first or :eq(0) in a selector. I\'m pretty sure that they\'ll always return the same object, but is one speedier than the other?

I\'m

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 15:11

    According to jQuery's source code, .first() is just a convenience wrapper for .eq(0):

    first: function() {
        return this.eq( 0 );
    },
    

提交回复
热议问题