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
28 lines (27 loc) • 769 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const isDOMChildNode_1 = __importDefault(require("./isDOMChildNode"));
const children_1 = __importDefault(require("./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);
* ```
*/
function siblings(elm) {
if (!isDOMChildNode_1.default(elm)) {
return [];
}
return children_1.default(elm.parentNode)
.filter((child) => child !== elm);
}
exports.default = siblings;