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

后端 未结 8 1168
忘掉有多难
忘掉有多难 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 16:17

    Heh. Researching this question I found this excellent post. And Also a post about this with the latest into on JQuery's learning site with specific tips to optimise speed!

    Worth noting that with the latest DOM specification, chances are you need not worry about performance in general. Only when you have created (or discover) a bottleneck.

    Optimise Selectors

    0 讨论(0)
  • 2020-12-04 16:19

    If you are concerned about performance, native getElementById is much much faster, but jQuery gives you very handy access to a lot of stuff. So, you might want to use something like :

    $( document.getElementById("some_id") ).jQueryCall();
    

    This will give you a better performance, and at the same time, allow you to use jQuery.

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