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

20 lines (19 loc) 438 B
import children from './children'; import isDOMChildNode from './isDOMChildNode'; /** * Find the index of a DOM element amongst its siblings * * @param elm - DOM element to find the index of * @return The index of `elm` * * @example * * ```ts * elmIndex(someDiv); * ``` */ export default function elmIndex(elm) { return isDOMChildNode(elm) ? children(elm.parentNode).indexOf(elm) : -1; }