UNPKG

unique-selector

Version:

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

13 lines (12 loc) 327 B
/** * Checks if the selector is unique * @param { Object } element * @param { String } selector * @return { Array } */ export function isUnique( el, selector ) { if( !Boolean( selector ) ) return false; const elems = el.ownerDocument.querySelectorAll( selector ); return elems.length === 1 && elems[ 0 ] === el; }