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

前端 未结 6 2007
悲&欢浪女
悲&欢浪女 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:42

    None of the other answers dealt with the case of using .children() or .find(">") to only search for immediate children of a parent element. So, I created a jsPerf test to find out, using three different ways to distinguish children.

    As it happens, even when using the extra ">" selector, .find() is still a lot faster than .children(); on my system, 10x so.

    So, from my perspective, there does not appear to be much reason to use the filtering mechanism of .children() at all.

提交回复
热议问题