Performance of jQuery selector with context

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

Leave a Comment