Given a jQuery object that represents a set of DOM elements, the .find()
method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements. The .find()
and .children()
methods are similar, except that the latter only travels a single level down the DOM tree.
The first signature for the .find()
method accepts a selector expression of the same type that we can pass to the $()
function. The elements will be filtered by testing whether they match this selector.
The first signature for the .find()
method accepts a selector expression of the same type that we can pass to the $()
function. The elements will be filtered by testing whether they match this selector. The expressions allowed include selectors like > p
which will find all the paragraphs that are children of the elements in the jQuery object.
Consider a page with a basic nested list on it:
<ul class="level-1">