Most efficient way to find elements in jQuery

后端 未结 8 1580
执念已碎
执念已碎 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:34

    The first selector should be faster because jQuery can use the built-in function "getElementsByTagName" to reduce the number of elements it needs to filter. The second one has to get all the elements in the DOM and check their class.

提交回复
热议问题