Title 1
Paragraph 1
Title 2
Paragraph 2
Title Three
Paragraph 3
Home >Web Front-end >JS Tutorial >Jquery search parent element operation method_jquery
The example in this article describes the Jquery search parent element operation method. Share it with everyone for your reference. The specific analysis is as follows:
1. parents() method
Format:
2. cloest method
Format:
The main differences between the cloest() and parents() methods are as follows:
① The former starts matching and searching from the current element, and the latter starts matching and searching from the parent element
② The former searches upwards step by step until it finds a matching element and then stops. The latter searches upwards until the root element, then puts these elements into a temporary collection, and then uses the given selector expression to filter.
③ The former returns 0 or 1 element, and the latter may contain 0, 1 or more elements.
3. parent() method
Format:
For example:
4. parentsUtil() method
Format:
For example:
5. offsetParent() method
is used to search for the positioned parent element of the first matching element. It is only valid for visible elements. The syntax is as follows:
This method finds the positioned element of the first matching element and returns a jQuery object wrapped by that element.
Comprehensive example:
Paragraph 1
Paragraph 2
Paragraph 3
The operation effect is as shown below:
I hope this article will be helpful to everyone’s jQuery programming.