jQuery TraversingLesson 22Free preview
jQuery Ancestors
This lesson is part of jQuery · All levels
Summary
The ancestor method is used to move over the DOM structure, that is, towards the parent and ancestor of an element. Navigation upwards is useful when you need to sort out the style of the container of the elements inside.
Key points
- Returns the direct parent of the selected element
- Return the whole chain of ancestors
- ParentsUntil() restrict search to certain ancestors
- Looking for a closest ancestor who matches the selector
- The result of traversing upwards can be directly given to another method
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.