Most efficient way to find elements in jQuery

后端 未结 8 1546
执念已碎
执念已碎 2020-12-16 18:19

If I have a CSS class which I only ever apply to form elements, eg:

Which of these two jQuery select

相关标签:
8条回答
  • 2020-12-16 18:55

    The first example goes a LOT faster when used with a context. The second example goes faster as well, but not by much. I expanded your example to compare with a context:

    http://jsbin.com/uluwe

    0 讨论(0)
  • 2020-12-16 18:57

    form.myForm IMO is much quicker as it only needs to be look at a subset/filtered set of elements and would not need to iterate the whole document.

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