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

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

    The native getElementById is faster. Jquery selector engine just wraps this for any #x selectors.

    Using the firebug console you can profile jquery in the following way. Not sure it works well for native api calls like getElementById.

    console.profile();
    $('#eleId');
    console.profileEnd();
    

提交回复
热议问题