jQuery :has() Selector
Example
Select all elements that contain an element within them
element:
$("p:has(span)")
Try it »
Definition and Usage
The :has() selector selects all elements that contain one or more elements matching the specified selector.
**Tip:** To select elements that contain multiple elements, use a comma (see the example below).
Syntax
$(":has(
selector
)")
| Parameters | Description |
|---|---|
| selector | Required. Specifies the element to select. |
| This parameter accepts any type of selector. |
Try it - Example
Select elements that contain multiple elements
How to select elements that contain multiple elements.
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 given element.
jQuery selector