What is fastest children() or find() in jQuery?

前端 未结 6 1950
悲&欢浪女
悲&欢浪女 2020-11-22 13:43

To select a child node in jQuery one can use children() but also find().

For example:

$(this).children(\'.foo\');

gives the same result

6条回答
  •  隐瞒了意图╮
    2020-11-22 14:43

    Those won't necessarily give the same result: find() will get you any descendant node, whereas children() will only get you immediate children that match.

    At one point, find() was a lot slower since it had to search for every descendant node that could be a match, and not just immediate children. However, this is no longer true; find() is much quicker due to using native browser methods.

提交回复
热议问题