UNPKG

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) 783 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var isDOMChildNode_1 = __importDefault(require("./isDOMChildNode")); var 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(function (child) { return child !== elm; }); } exports.default = siblings;