The difference between $ ("# orderedlist"). Find ("li") and $ ("# orderedlist li")

What's the difference between:

$("#orderedlist").find("li")

... and ...

$("#orderedlist li"). 

When can I use another?

+3
source share
3 answers

As a rule, he is not.

Only in complex selectors does it make sense to break them into different methods.

0
source

$("#orderedlist").find("li")faster because it uses native JavaScript.
$("#orderedlist li")will be slower because it calls Sizzle when you pass the selector.
Both do the same thing anyway.

+1
source

In this situation, I will use .find ():

$("#orderedlist").show().find("li").css("color", "red");

But if #orderedlist is visible, and I just wanted to change the color directly

on red i would use
$("#orderedlist li").css("color", "red");

I think this is just a question of what you are doing.

0
source

All Articles