code: function matches(elem, selector) {
    // We'll use querySelectorAll to find all element matching the selector,
    // then check if the given element is included in that list.
    // Executing the query on the parentNode reduces the resulting nodeList,
    // document doesn't have a parentNode, though.
    var nodeList = ( elem.parentNode || document ).querySelectorAll( selector ) || [],
        i = nodeList.length;
  
    // loop on the nodeList
    while ( i-- ) {
      if ( nodeList[i] == elem ) { return true; }
    }
    return false;
  }
docs: ------------------------------ Match DOM element to selector ------------------------------