jQuery .siblings() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Traversing

Definition

.siblings() gets the siblings of each element in the current set — all elements that share the same parent, excluding the element itself. Optional selector filter. Available since jQuery 1.0.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("li.third-item").siblings()           → 1, 2, 4, 5 (not 3)
$("p").siblings(".selected")            → filtered siblings only

Parent
├─ item 1  ← sibling
├─ item 2  ← sibling
├─ item 3  ← start (excluded)
├─ item 4  ← sibling
└─ item 5  ← sibling

.next() / .prev()     → one neighbor
.nextAll() / .prevAll() → one direction
.siblings()           → both directions, minus self
CallWhat it does
Starting setElements whose peers are collected
SelectorKeeps only matching siblings
SelfAlways excluded from the result

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the starting element(s): $("li.third-item").
Step 2Call .siblings() for all peers, or .siblings("sel") to filter.
Step 3Remember: the start element is never included.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Official: $("li.third-item").siblings()

Get every sibling of the third list item (jQuery API example).

jQuery
var $hits = $("li.third-item").siblings();
console.log($hits.length);
console.log($hits.map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. Start at item 3. $("li.third-item") is the root.
  2. Collect peers. Same parent ul, both directions.
  3. Skip self. Item 3 is not in the result.

Example 2 — Filter: .siblings(".selected")

Keep only siblings that match a selector (official pattern).

jQuery
var $hits = $("p.start").siblings(".selected");
console.log($hits.length);
console.log($hits.map(function () {
  return this.textContent.trim();
}).get().join(", "));
Try It Yourself

How It Works

  1. Start at p.start. One paragraph in a group.
  2. List all siblings. Other p (and any peer tags) under the parent.
  3. Filter. .selected keeps only marked peers.

Example 3 — vs .next() and .prev()

One neighbor each way versus all peers.

jQuery
var $el = $("li.third-item");
console.log("siblings:", $el.siblings().map(function () {
  return this.textContent.trim();
}).get().join(", "));
console.log("next:", $el.next().text().trim());
console.log("prev:", $el.prev().text().trim());
Try It Yourself

How It Works

  1. .siblings(). Four peers on both sides.
  2. .next(). Immediate following item only.
  3. .prev(). Immediate preceding item only.

Frequently Asked Questions

.siblings() returns every sibling of each element in the current set — elements that share the same parent, excluding the element itself. An optional selector filters which siblings are kept. Available since jQuery 1.0.
.next() and .prev() return at most one immediate neighbor. .siblings() returns all siblings on both sides. From list item 3, .next() is item 4 only; .siblings() is items 1, 2, 4, and 5.
.nextAll() is only following siblings; .prevAll() is only preceding. .siblings() combines both directions (minus self).
No. The matched element is never in the result. Official demo from item 3 styles 1, 2, 4, and 5 — not 3.
When the starting set has multiple mutual siblings, plain .siblings() can return members of the original set. Chain .not($collection) for an exclusive list of other siblings only.
Yes. Pass a selector: $("p").siblings(".selected") keeps only sibling elements that match .selected.

Next: .each() Method

Remove elements from a set — useful after .siblings() for exclusive peers.

.each() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful