The general sibling combinator prev ~ siblings selects all following siblings that match siblings, share the same parent as prev, and appear after it in the DOM. Wider reach than +. Available since jQuery 1.0 (standard CSS).
Remember
$("prev ~ siblings")
$("#prev ~ div") → every div sibling after #prev
$("h2 ~ p") → every p sibling after each h2
$("h2 + p") → only the immediate next p
$("div p") → p nested inside div (descendant)
Name the starting sibling, add ~, then filter which following siblings to keep.
Confirm targets are siblings under the same parent (not nested children).
Write $("prev ~ siblings") — for example $("#prev ~ div").
Chain a method on the whole following set.
If you need only the immediate neighbor, switch to +.
Piece
Required?
Role
prev
Yes
Selector for the starting sibling
~
Yes
General sibling combinator
siblings
Yes
Filter for following siblings to keep
Pseudocode
Pseudocode
for each element P matching "prev":
for each following sibling S of P:
if S matches "siblings":
keep S
// skipped: elements before P
// skipped: nested children of siblings (nieces)
return jQuery(kept elements)
Reference
Cheat Sheet
Keep these facts handy while writing general sibling selectors.
Topic
Detail
Syntax
$("prev ~ siblings")
Meaning
All following matching siblings
Direction
After prev only (not before)
Parent rule
Same parent required
vs +
~ = many; + = one
vs space
Siblings, not nested descendants
vs .nextAll()
Selector vs traversal method
Since
jQuery 1.0 (standard CSS)
Try it
Live Preview
Pick a combinator against a small sample DOM and see which nodes match.
Sample markup mirrors the official #prev ~ div pattern plus heading siblings.
before
prev
sib1
sib2niece-wrap
niece
span-sib
sib3
Section
Lead
Second
Third
Result
$("#prev ~ div")
matched: 3
tags: DIV, DIV, DIV
/* ~ = all following siblings */
Code
jQuery Examples
Short, copy-ready snippets. Open a browser console with jQuery loaded, or use Try It Yourself for a live editor.
Example 1 — Official Demo: #prev ~ div
Select every div sibling that follows #prev (jQuery API example).
true
3
Same following divs via ~ and .nextAll("div")
How It Works
Selector path.$("#prev ~ div") queries the document in one string.
Traversal path. Start at #prev, then take every following sibling that is a div.
Same set. Lengths match for the same markup.
When to choose. Static query → ~. Already holding the start node → .nextAll().
Edge Cases & Pitfalls
Check these before relying on ~ in real projects.
niece
Nested children are not siblings
Official demo: a “niece” div inside a sibling is skipped. ~ never walks into nested trees.
before
Nothing before prev matches
~ is forward-only. Elements that appear above prev in the markup are never selected.
mix-up
~ ≠ + ≠ space
+ = one neighbor. ~ = all following. Space = nested descendants. Pick the combinator that matches your tree shape.
scope
Wide matches on large pages
$("div ~ p") can be huge. Scope with an id/class on prev, or start from a container before querying.
Compatibility
Browser Support
The general sibling combinator is standard CSS and has worked in jQuery since 1.0. Modern browsers implement it in native querySelectorAll.
✓ CSS · jQuery 1.0+
jQuery "prev ~ siblings"
Supported in all modern browsers. Native: document.querySelectorAll("h2 ~ p"). Universal CSS general sibling combinator.
100%Standard CSS selector
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
General sibling (~)Universal
Bottom line: Safe everywhere jQuery runs. Use ~ for every following match; use + when you need only the immediate neighbor.
Analysis
Performance Notes
Approach
Cost
Best for
$("prev ~ siblings")
Native CSS when possible
Static following-sibling queries
$("prev").nextAll("f")
Traversal from a set
Starting from held elements
$("prev + next")
Smaller result set
Immediate neighbor only
Prefer a specific prev (id/class) so ~ does not scan more of the tree than you need. Reach for + when one sibling is enough.
Remember
Key Takeaways
Role:prev ~ siblings selects all following matching siblings.
Reach: wider than +; still same-parent siblings only.
Skips: nodes before prev, and nested nieces/nephews.
Traversal: pair with .nextAll() when you already hold the start node.
One line:$("prev ~ siblings") means “every matching sibling after prev” — not nested, not before.
Frequently Asked Questions
The general sibling combinator prev ~ siblings selects every element matching siblings that comes after a sibling matching prev, as long as both share the same parent. $("h2 ~ p") matches all paragraphs after each h2, not only the first one.
+ reaches only the immediately following sibling. ~ extends that reach to all following siblings that match. $("h2 + p") picks one lead paragraph; $("h2 ~ p") picks every following paragraph sibling.
A space matches nested descendants inside an ancestor. ~ matches siblings at the same level. $("div p") finds paragraphs inside divs; $("h2 ~ p") finds paragraphs that follow an h2 as siblings.
No. Only siblings that appear after prev in the DOM. Elements before prev, and nested children of siblings (nieces/nephews), are skipped.
$("prev ~ siblings") is a one-shot CSS selector. .nextAll("siblings") is a traversal method when you already hold a jQuery collection and want every following sibling that matches a filter.
Since jQuery 1.0. It is standard CSS; modern browsers support it via document.querySelectorAll("h2 ~ p").