jQuery size() method vs length attribute

后端 未结 9 2205
天命终不由人
天命终不由人 2020-12-05 22:20

Is there any difference between $(\".selector\").size() and $(\".selector\").length ?

相关标签:
9条回答
  • 2020-12-05 23:12

    They will both give you the same result but .length is slightly faster.

    See http://api.jquery.com/size/:

    The .length property is a slightly faster way to get this information.

    0 讨论(0)
  • 2020-12-05 23:19

    No. size() returns length. By using length you only avoid one extra method call.

    0 讨论(0)
  • 2020-12-05 23:19

    Length returns the same thing and is slightly faster according to the jQuery documentation.

    Source: http://api.jquery.com/size/

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