Selecting by hierarchy (Must know)

This chapter explains how to combine the selectors seen so far using hierarchy operators to retrieve elements by their relationship in the DOM.

Getting ready

Before we dive into the code, we should be aware of the weapons in our belt. The following is a table describing all of the selectors that belong to this category:

Name

Identifying Character

Syntax

Description

Child

>

Parent > Children

(for example, #title > .red)

Selects all direct children "Children" of the parent specified by "Parent".

Descendant

(space)

Ancestor Descendants

(for example, .wrapper .red)

Selects all descendants "Descendants" having in their ancestor list "Ancestor".

Next Adjacent

+

Prev + Next

(for example. h1 + p)

Selects ...

Get Instant JQuery Selectors now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.