vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
22 lines (21 loc) • 472 B
JavaScript
import isDOMChildNode from './isDOMChildNode';
import children from './children';
/**
* Get all sibling elements of a given DOM element
*
* @param elm - DOM element to find siblings of
* @return Collection of sibling elements
*
* @example
*
* ```ts
* siblings(someElement);
* ```
*/
export default function siblings(elm) {
if (!isDOMChildNode(elm)) {
return [];
}
return children(elm.parentNode)
.filter((child) => child !== elm);
}