URL: http://groups.google.com/group/jquery-en/msg/ec43a643e0f0bd54

For the performance interested jQuery users please check out this thread

For the impatient, read Stephens reply He benchmarked what I asked and concluded that $("p", $("#foo")) is much faster in jQuery 1.3.2. I've been coding this style in jQuery for all recent projects so I'm happy with this outcome.

UPDATE

John Resig himself joined in on the discussion and had this to say:

"You should always use $("#foo").find("p") in favor of $("p", $("#foo")) - the second one ends up executing $(...) 3 times total - only to arrive at the same result as doing $("#foo").find("p")."

UPDATE 2

Not only did John join in on the discussion but it also made him work on jQuery 1.3.3 (not yet released at the time of writing) so that it doesn't matter which format you use you get the same performance. See the benchmark here

Comments

h3

Why not simply: $("#foo").find("p");

The syntax is more clear and readable, and jQuery isn't called twice.

Performance wise, they are practically equivalent.

Peter Bengtsson

See my update in the blog post.

Your email will never ever be published.

Previous:
Propeller Island City Lodge Orange Room February 23, 2009
Next:
Sandisk SSD v/s HDD March 4, 2009 Misc. links
Related by category:
Switching from Next.js to Vite + wouter July 28, 2023 JavaScript
How to SSG a Vite SPA April 26, 2025 JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
swr compared to @tanstack/react-query August 30, 2024 JavaScript
Related by keyword:
Benchmark compare Highlight.js vs. Prism May 19, 2020 Node, JavaScript
Fastest way to uniqify a list in Python August 14, 2006 Python
How to fadeIn and fadeOut like jQuery but with Cash August 24, 2021 JavaScript
The ideal number of workers in Jest October 8, 2018 Python, React