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
26 lines (25 loc) • 716 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const children_1 = __importDefault(require("./children"));
const isDOMChildNode_1 = __importDefault(require("./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);
* ```
*/
function elmIndex(elm) {
return isDOMChildNode_1.default(elm)
? children_1.default(elm.parentNode).indexOf(elm)
: -1;
}
exports.default = elmIndex;