jquery, performance-wise what is faster getElementById or jquery selector?

后端 未结 8 1202
忘掉有多难
忘掉有多难 2020-12-04 15:45

What is better from performance wise document.getElementById(\'elementId\') or $(\'#elementId\') ? How can I calculate the speed by myself?

8条回答
  •  误落风尘
    2020-12-04 15:53

    getElementById is faster, because it uses native code. The jQuery selector will also use getElementById, but it first needs to do a lot of tests and comparisons on the text.

提交回复
热议问题