Performance of jQuery Selectors with ID

后端 未结 9 2202
有刺的猬
有刺的猬 2021-01-12 10:52

I know in jQuery if we use ID to select elements,it\'s so efficient.I have a question about this selectors:

please consider this 3 selectors:

         


        
9条回答
  •  盖世英雄少女心
    2021-01-12 11:58

    A direct ID selector will always be the fastest.

    I've created a simple test case based on your question...

    http://jsperf.com/selector-test-id-id-id-id-class

    Selecting nested ID's is just wrong, because if an ID is unique (which it should be), then it doesn't matter if it's nested or not.

提交回复
热议问题