function closestDown(element, nodes, until) {
  var matched = [];
  var elementToCheck = element;

  while (elementToCheck) {
    elementToCheck = closest(elementToCheck, nodes, until);

    if (!elementToCheck || until && !until.contains(elementToCheck)) {
      break;
    }

    matched.push(elementToCheck);

    if (elementToCheck.host && elementToCheck.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
      elementToCheck = elementToCheck.host;
    } else {
      elementToCheck = elementToCheck.parentNode;
    }
  }

  var length = matched.length;
  return length ? matched[length - 1] : null;
}
Goes "down" the DOM tree (including given element) until it finds an element that matches the nodes or nodes name.

@param {HTMLElement} element Element from which traversing is started
@param {Array} nodes Array of elements or Array of elements name
@param {HTMLElement} [until]
@returns {HTMLElement|null}