When is one preferred over the other when searching for nested Divs?
The find() method traverses the entire Dom whereas the children() method gets the immediate children of the node. The children() method is to get the immediate children of the node.
difference between find() and children() methods in jquery : Both find() and childern() are jquery methods. find() method is used to search the more then one level down the tree (DOM tree) while children() method is uesd to find the single level down the tree. childern() method is faster than find() method.
Find method is used to find all levels down the DOM tree but children find single level down the DOM tree.
As said here, the main difference is that with . contents you'll get a list, while with . children you'll get a generator.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With