[Home] > Snippets  > Browser  > DOM  >  Get all siblings of an element

Get all siblings of an element

JavaScript

const siblings = (ele) => [].slice.call(ele.parentNode.children).filter((child) => child !== ele)

TypeScript

const siblings = (ele: Node): Node[] => (ele.parentNode ? [].slice.call(ele.parentNode.children).filter((child) => child !== ele) : [])