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

Get all siblings of an element

JavaScript version

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

TypeScript version

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