jQuery traversal - descendants
jQuery Traversal - Descendants
Descendants are children, grandchildren, great-grandchildren, etc.
With jQuery, you can traverse down the DOM tree to find the descendants of an element.
Traverse down the DOM tree
The following are two jQuery methods for traversing down the DOM tree:
children()
find()
jQuery children() method
children() method returns all direct child elements of the selected element.
This method will only traverse the DOM tree one level down.
div (当前元素)p (儿子元素) span (孙子元素)
p (儿子元素) span (孙子元素)
jQuery find() method
The find() method returns the descendant elements of the selected element, all the way down to the last descendant.
div (当前元素)p (儿子元素) span (孙子元素)
p (儿子元素) span (孙子元素)