UNPKG

unique-selector

Version:

Given a DOM node, return a unique CSS selector matching only that element

37 lines (31 loc) 802 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNthChild = getNthChild; var _isElement = require('./isElement'); /** * Returns the selectors based on the position of the element relative to its siblings * @param { Object } element * @return { Array } */ function getNthChild(element) { var counter = 0; var k = void 0; var sibling = void 0; var parentNode = element.parentNode; if (Boolean(parentNode)) { var childNodes = parentNode.childNodes; var len = childNodes.length; for (k = 0; k < len; k++) { sibling = childNodes[k]; if ((0, _isElement.isElement)(sibling)) { counter++; if (sibling === element) { return ':nth-child(' + counter + ')'; } } } } return null; }