On 12/16/06, David <[EMAIL PROTECTED]> wrote:

I asked that question a few days ago, so i will pass the knowledge :)

>
> 1, $('#id')
calls the javascript function getElementById so that is the fastest.
> 2, $('tag#id')
is slow because jquery gets all the tags first and then searches for the
id



A possible way to speed up $("tag#id") is to do $("#id").is("tag")

That will first run getElementById, and then test if it matches the
selector.

You would probably see dramatic speed gains by converting something like:

$(".class > .otherClass tr#id td#id") into $("#id").id(".class > .otherClass
tr#id td")

since a search by ID at any point is really just a search by ID which also
tests whether that node matches the early selectors/filters.



> 3, $('.class',context)
the performance depends on the context


Well sort of.  $(".class", context) where context is $("#id")[0] is the same
thing as $("#id .class")

4, $('#id .class')
> 5, $('.class1 .class2')
4 is faster than 5 because of the getElementById function


Indeed. 4 is way faster than 5. Anytime you can narrow something down by ID,
do it. getElementById is blazingly fast, and will help all around.

This is was i understood from the answers. Correct me if i made a
mistake somewhere.


David



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/




--
Yehuda Katz
Web Developer | Wycats Designs
(ph)  718.877.1325
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to