jquery $('.class').each() how many items?

后端 未结 4 917
猫巷女王i
猫巷女王i 2020-12-29 01:24

When looping over a group of items using jquery selectors is there a way to find out how many items there are on the collection?

4条回答
  •  梦谈多话
    2020-12-29 01:54

    If you are using a version of jQuery that is less than version 1.8 you can use the $('.class').size() which takes zero parameters. See documentation for more information on .size() method.

    However if you are using (or plan to upgrade) to 1.8 or greater you can use $('.class').length property. See documentation for more information on .length property.

提交回复
热议问题