JQuery difference between searching 'children' and 'find'?

后端 未结 3 884
Happy的楠姐
Happy的楠姐 2021-01-07 19:16

When is one preferred over the other when searching for nested Divs?

相关标签:
3条回答
  • 2021-01-07 19:47

    The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.

    Source: http://api.jquery.com/children/

    0 讨论(0)
  • 2021-01-07 19:49

    Find is recursive, where children looks only 1 level deep in the DOM. Check out this: http://blog.ekini.net/2009/03/16/jquery-children-vs-find-which-is-faster/

    Note: that is actually references a Stackoverflow post.

    Either way, that should help answer your question. If you need to search more than one level use Find, if not use children as it is faster.

    0 讨论(0)
  • 2021-01-07 19:52

    find() vs childern() in jQuery

    find() – search through the matched elements in all the subsequent level ,All levels down.

    children() – search through the matched elements’ child only (single level down).

    0 讨论(0)
提交回复
热议问题