jQuery 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() methodReturns all direct child elements of the selected element.
This method will only traverse the DOM tree one level down.
The following example returns all direct child elements of each
div (当前元素)p (儿子元素) span (孙子元素)
p (儿子元素) span (孙子元素)
Run the program to try it
You can also use optional parameters to filter the search for child elements.
The following example returns all
elements with class name "1" that are direct children of
div (当前元素)p (儿子元素) span (孙子元素)
p (儿子元素) span (孙子元素)
Run the program to try it
jQuery find() method
The find() method returns the descendant elements of the selected element, all the way down to the last descendant.
The following example returns all elements that are descendants of