text: var matches = require('matches-selector')
  
  module.exports = function (element, selector, checkYoSelf, root) {
    element = checkYoSelf ? {parentNode: element} : element
  
    root = root || document
  
    // Make sure `element !== document` and `element != null`
    // otherwise we get an illegal invocation
    while ((element = element.parentNode) && element !== document) {
      if (matches(element, selector))
        return element
      // After `matches` on the edge case that
      // the selector matches the root
      // (when the root is not the document)
      if (element === root)
        return  
    }
  }