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

后端 未结 8 1201
忘掉有多难
忘掉有多难 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: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.

提交回复
热议问题