# Get all siblings of an element

Return the other element children of the element’s parent.

Canonical: https://1loc.dev/dom/get-all-siblings-of-an-element/
Version: 1.0.0
Runtime: JavaScript · modern browsers (DOM)
Verification: Usage lines executed in headless Chromium against the fixture markup; no external services
Updated: 2026-10-28

## Implementation

```javascript
function siblings(element) { return element.parentElement ? [...element.parentElement.children].filter(child => child !== element) : []; }
```

## Usage

Markup:

```html
<ul><li id="a">A</li><li id="b">B</li><li id="c">C</li></ul>
```

Script:

```javascript
siblings(document.querySelector('#b')).map(element => element.id); // → ['a', 'c']
siblings(document.createElement('li')); // → []
```

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

## Limits

- Element siblings only: text and comment nodes are skipped. The original threw a TypeError for an element without a parent; this version returns [].

The function does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/get-all-siblings-of-an-element.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Returns [] for an element without a parent instead of throwing. Executed in Chromium. Original MDX retained as inert source evidence.
