code: function (selector, root) {
          if (!isElement(root)) {
              return null
          }
  
          var Closest = Element.prototype.closest ||
              function (sel) {
                  var element = this;
                  if (!document.documentElement.contains(element)) {
                      return null
                  }
  
                  do {
                      if (element.matches(sel)) {
                          return element
                      }
  
                      element = element.parentElement;
                  } while (element !== null)
  
                  return null
              };
  
          var el = Closest.call(root, selector);
  
          return el === root ? null : el
      }
docs: Finds closest element matching selector.