JQuery speed when binding objects and their descendants

Regarding speed and resource usage, if I save the html of the page as a jquery object like:

var meHTML = $('html')


Should I be referring to other objects by saying

var someID = meHTML.find('#someID')



var someID = $('#someID')


I'm sure it's probably only minimal, but I'm curious to know what the differences might be.

Thanks in advance for any advice.


source to share

1 answer

If you look at the source for the call $("#id")

, you can see that they have incremented one id using document.getElementById

and set the dial length to 1


The source for .find

, however, is more expensive as the selector is passed to Sizzle. Also, it checks for duplicates in the result set, for example, which is optional with an ID. This will result in a longer and slower code path.

So, it $("#id")

should be faster.



All Articles