jQuery :has()Selector
Examples
Select all <p> elements that contain a <span> element inside them:
$("p:has(span)")
Try it Yourself »
Definition and Usage
The :has() selector selects all elements that contain one or more elements inside them, matching the specified selector.
Tip:To select elements that contain multiple elements inside them, use a comma (see example below).
Syntax
$(":has(selector)")
| Parameter | Description |
|---|---|
| selector | Required. Specifies the element(s) to select. This parameter accepts any type of selector. |
Try it Yourself - Example
Select elements that contain multiple elements
How to select elements that contain multiple elements inside them.
Select elements that do not contain the specified element
Use the :not selector together with the :has selector to select elements that do not contain the specified element.
Other Extensions
jQuery Selectors