code: function closest(node, parentSelector) {
    var cursor = node;
  
    if (!parentSelector || typeof parentSelector !== 'string') {
      throw new Error('Please specify a selector to match against!');
    }
  
    while (cursor && !matches(cursor, parentSelector)) {
      cursor = cursor.parentNode;
    }
  
    if (!cursor) {
      return null;
    } else {
      return cursor;
    }
  }
docs: get closest element that matches selector starting with the element itself and traversing up through parents.
  @param  {Element} node
  @param  {string} parentSelector
  @return {Element|null}