Stig Perez
Stig Perez

Reputation: 3813

Difference between ways of selecting descendants

With the risk of being redirected to a dublicate question, what is the difference between using $("ul li") and $("ul").find("li")?

Upvotes: 1

Views: 46

Answers (2)

Jashwant
Jashwant

Reputation: 29005

$("ul").find("li") is faster than $("ul li").

$("ul li") is going to be changed into $("ul").find("li") after some checks and breaking.

find() appeared faster than children() to me in single level selections.

Upvotes: 0

Justin Helgerson
Justin Helgerson

Reputation: 25521

You may find this similar question of interest: What is the fastest method for selecting descendant elements in jQuery?

If you only need first level children, using .children() will give you a performance boost since there is less to interrogate.

Upvotes: 1

Related Questions