English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :has() Selector

jQuery Selectors

:has() selector selects all elements that contain one or more elements within them, matching the specified selector.

Syntax:

$":has(selector)")

Example

Select all <p> elements that contain at least one <span> element:

$("document").ready(function(){
  $("p:has(span)").css("background", "coral");
});
Test and See‹/›

Parameter Value

ParameterDescription
selectorAny Selector

jQuery Selectors