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

jQuery ~ Sibling Selector

jQuery Selectors

The general sibling selector (~) selects all sibling elements of the specified element.

Sibling elements must have the same parent, butnextNot necessarily adjacent toAfter prev.

Syntax:

$("prev ~ next")

Example

Select all <p> elements that are siblings of <div> elements:

$("document").ready(function(){
  $("div ~ p").css("background", "mediumpurple");
});
Test and see‹/›

Parameter Value

ParameterDescription
prevAny valid selector
nextA selector that filters the elements that are at the same level as the first selector

jQuery Selectors