Performance of jQuery selector with context

后端 未结 6 1442
南方客
南方客 2020-12-01 05:26

I was reading this article by Brandon Aaron here, about how jquery context may help. So i thought of doing a test of my own. So this is what I did.

  1. Created

6条回答
  •  旧时难觅i
    2020-12-01 06:23

    Context really helps when you have a much larger DOM that you are searching through. Searching for IDs is already very fast and context doesn't really help that much in that case. Where context can really make a difference is when you are selecting by tag name or class.

    Try testing like this: http://jsbin.com/aciji4/4

    you can really see the timing get better for context when you bump up number of items in the DOM like this: http://jsbin.com/aciji4/6

提交回复
热议问题