Performance of jQuery Selectors with ID

后端 未结 9 2019
有刺的猬
有刺的猬 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:50

    Also, if you need nested selectors, it's faster to use $().find().find()

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

    $('#Mytbl .MyClass')
    $('#Mytbl').find('.MyClass')
    

    The latter is about 65% faster.

提交回复
热议问题