jQuery .siblings() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
All siblings

What You’ll Learn

The .siblings() traversing method moves sideways in the DOM — it returns every sibling of each matched element except the element itself, optionally filtered by a selector. This tutorial covers the official list-item and multi-list hilite demos, selector filtering, comparisons with .next(), .prev(), .nextAll(), and .prevAll(), and practical tab-navigation patterns.

01

Both ways

All peer elements

02

Excludes self

Never in result

03

Selector

.siblings(".x")

04

vs .nextAll()

Both vs ahead

05

Exclusive list

.not($collection)

06

Since 1.0

Core API

Introduction

Siblings share the same parent — think of list items in a ul, tabs in a toolbar, or paragraphs in a container. When you need every other element at that level — not just the next or previous neighbor — reach for .siblings().

Available since jQuery 1.0, .siblings([selector]) constructs a new jQuery object from all sibling elements of each item in the current set, excluding the source element itself. It does not descend into children or climb to ancestors — it stays on the same level of the tree, searching both directions among peers.

Understanding the .siblings() Method

Given a jQuery object representing a set of DOM elements, .siblings() looks at each element’s parent and collects every other child element — all previousElementSibling and nextElementSibling nodes in the chain. The source element is never included. When you pass a selector, only siblings that match are kept.

This is broader than .next() or .prev(), which each return at most one neighbor, and broader than .nextAll() or .prevAll(), which cover only one direction. .siblings() is the go-to method for “everyone else at this level” — perfect for tab UIs, accordion headers, or styling all other list items around a selection.

💡
Beginner Tip

$("li.third-item").siblings() returns list items 1, 2, 4, and 5 — not item 3. $("li.third-item").nextAll() returns only 4 and 5; .prevAll() returns only 1 and 2.

📝 Syntax

General form of .siblings:

jQuery
.siblings( [ selector ] )

Parameters

  • selector (optional) — a string containing a selector expression. Only siblings matching this selector are included in the result.

Return value

  • A new jQuery object containing all siblings of each element in the current set, excluding the elements themselves (filtered when a selector is provided).

Official jQuery API list example

jQuery
$( "li.third-item" ).siblings().css( "background-color", "red" );

// Red background on list items 1, 2, 4, and 5 — every sibling except item 3

⚡ Quick Reference

GoalCode
All siblings except self$("li.active").siblings()
Siblings matching a class$("p").siblings(".selected")
Exclusive list (multi-select)$collection.siblings().not($collection)
Following siblings only$("li.start").nextAll()
Preceding siblings only$("li.end").prevAll()
Immediate next neighbor$("li").next()

📋 .siblings() vs .next() vs .prev() vs .nextAll() vs .prevAll()

Five sibling methods — same parent level, different scope and direction.

.siblings()
both ways

All siblings except self — optional filter

.next()
+1 forward

One immediately following sibling

.prev()
-1 backward

One immediately preceding sibling

.nextAll()
all ahead

Every following sibling after current

.prevAll()
all behind

Every preceding sibling before current

Examples Gallery

Examples 1–3 follow the official jQuery API documentation. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demos for all-sibling traversal.

Example 1 — Official Demo: Style All Other List Items

From the third list item, style every sibling — the core official lesson.

jQuery
$( "li.third-item" ).siblings().css( "background-color", "red" );
Try It Yourself

How It Works

Item 3’s siblings are items 1, 2, 4, and 5. .siblings() returns all of them — unlike .next(), which would return only item 4.

Example 2 — Official Demo: Count Unique Siblings Across Three Lists

Find every sibling of highlighted items across multiple lists and count the unique set.

jQuery
var len = $( ".hilite" ).siblings()

  .css( "color", "red" )

  .length;

$( "b" ).text( len );
Try It Yourself

How It Works

Each .hilite element contributes its siblings. jQuery unions the results and removes duplicates automatically — the .length property counts the unique sibling set across all three lists.

Example 3 — Official Demo: Keep Only Siblings Matching .selected

Filter siblings — include only those with class selected.

jQuery
$( "p" ).siblings( ".selected" ).css( "background", "yellow" );
Try It Yourself

How It Works

Unlike .next(".selected"), which checks only the immediate next neighbor, .siblings(".selected") scans every sibling in both directions and keeps those that match the selector.

📈 Practical Patterns

Compare sibling methods, then build a tab UI with .siblings().

Example 4 — .siblings() vs .nextAll() vs .prevAll()

See how scope changes when you collect peers in both directions vs one direction only.

jQuery
var $anchor = $( "#siblings-demo li.third-item" );

$anchor.siblings().css( "color", "green" );

$anchor.nextAll().css( "color", "blue" );

$anchor.prevAll().css( "color", "red" );



// .siblings() → 1,2,4,5 | .nextAll() → 4,5 | .prevAll() → 1,2
Try It Yourself

How It Works

All three methods stay among siblings under the same ul, but each defines a different slice. Pick .siblings() when you need every peer except the anchor element.

Example 5 — Tab UI: Remove Active Class from Sibling Tabs

Real-world pattern: on tab click, activate the clicked tab and deactivate all its siblings.

jQuery
$( ".tab" ).on( "click", function () {

  $( this ).addClass( "active" )

    .siblings( ".tab" )

    .removeClass( "active" );

});
Try It Yourself

How It Works

Tab buttons in a nav bar are siblings. .siblings(".tab") targets every other tab without affecting unrelated elements in the container — a concise exclusive-selection pattern.

🚀 Common Use Cases

  • Tab navigation$(this).addClass("active").siblings().removeClass("active").
  • Accordion headers — close every other panel header when one opens.
  • List item highlighting — official pattern: style all siblings except the selected item.
  • Toolbar buttons — deactivate sibling toggle buttons when one is pressed.
  • Filtered sibling sets$("p").siblings(".selected") to target matching peers only.
  • Exclusive multi-select$collection.siblings().not($collection) when mutual siblings are in the starting set.

🧠 How .siblings() Collects Peer Elements

1

Start with source elements

jQuery object holds one or more DOM nodes.

Input
2

Walk sibling chain

Collect all element siblings in both directions under the same parent.

Traverse
3

Exclude self & filter

Remove source element; apply selector if provided.

Filter
4

Return & chain

New jQuery object — empty when no matching siblings exist.

📝 Notes

  • Available since jQuery 1.0 — optional selector argument included from the start.
  • The source element is never included in the result — only its peers.
  • Text nodes and comments between elements are skipped — jQuery uses element siblings only.
  • When the starting collection has multiple mutual siblings, they may appear in each other’s results — use .not($collection) for an exclusive list.
  • Empty result returns an empty jQuery object — safe to chain without errors.
  • Pair with .nextAll() or .prevAll() when you need one direction only, and .next() / .prev() for a single neighbor.

Browser Support

.siblings() has been part of jQuery since 1.0+. It relies on standard sibling traversal with no browser-specific behavior beyond jQuery itself.

jQuery 1.0+

jQuery .siblings()

Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Native equivalent: walk previousElementSibling and nextElementSibling — jQuery adds selector filtering, deduplication, and collection semantics.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.siblings() Universal

Bottom line: Safe in any jQuery project. Use .siblings() for all peers except self; use .nextAll() or .prevAll() when you need one direction only.

Conclusion

The jQuery .siblings() method returns every sibling of each element in the current collection, excluding the elements themselves. It is the simplest way to reach all peers at the same DOM level in both directions.

Remember the official list lesson: from item 3, items 1, 2, 4, and 5 get the red background — not item 3. Use .nextAll() or .prevAll() when you need one direction only, .next() or .prev() for a single neighbor, and $collection.siblings().not($collection) when mutual siblings must be excluded from the result.

💡 Best Practices

✅ Do

  • Use .siblings() when you need every peer except the current element
  • Filter with .siblings(selector) to target specific sibling types
  • Use .siblings().not($collection) for exclusive lists from multi-element collections
  • Pair with tab and toggle UIs where only one sibling should stay active
  • Prefer .nextAll() or .prevAll() when direction matters

❌ Don’t

  • Expect the source element in the result — it is always excluded
  • Use .siblings() when you need only following siblings — use .nextAll()
  • Confuse siblings with children — use .children() or .find() for descendants
  • Assume text nodes count — only element siblings are returned
  • Forget that mutual siblings in a multi-select can reappear in plain .siblings()

Key Takeaways

Knowledge Unlocked

Five things to remember about .siblings()

All peers except self.

5
Core concepts
02

Excludes self

Never included

Rule
03

.nextAll()

Ahead only

Compare
? 04

Selector

All matching

Filter
05

.not()

Exclusive list

Pattern

❓ Frequently Asked Questions

.siblings() returns every sibling of each element in the current jQuery collection — all elements that share the same parent, excluding the element itself. It searches both backward and forward along the sibling list. An optional selector filters which siblings are kept.
.next() and .prev() each return at most one sibling — the immediate neighbor in one direction. .siblings() returns all siblings on both sides of the element. From list item 3, .next() gives item 4 only; .siblings() gives items 1, 2, 4, and 5.
.nextAll() returns only following siblings; .prevAll() returns only preceding siblings. .siblings() combines both directions into one set (minus the source element). Use .siblings() when you need peers at the same level regardless of position.
No. The matched element itself is never part of the result. That is why the official list demo styles items 1, 2, 4, and 5 from item 3 — item 3 is excluded. When your collection contains multiple elements that are mutual siblings, both may appear in each other's .siblings() results.
When the starting collection has more than one element and those elements are siblings of each other, plain .siblings() can return members of the original collection. Chaining .not($collection) removes them so you get an exclusive list of other siblings only — useful for bulk tab or list operations.
It scans every sibling under the same parent and keeps only those matching the selector. Unlike .next(selector), which tests only the immediate next neighbor, .siblings('.selected') finds all sibling elements with class selected — both before and after the source element.
Did you know?

The jQuery API documentation explicitly recommends $collection.siblings().not($collection) when your starting set contains more than one element that are mutual siblings. Plain .siblings() on each element can return the other members of the original collection — chaining .not($collection) strips them out for a truly exclusive peer list.

Back to jQuery Traversing

Explore more DOM traversal methods as the collection grows.

Traversing hub →

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.

6 people found this page helpful