function isChildOf(child, parent) {
  var node = child.parentNode;
  var queriedParents = [];

  if (typeof parent === 'string') {
    queriedParents = Array.prototype.slice.call(child.ownerDocument.querySelectorAll(parent), 0);
  } else {
    queriedParents.push(parent);
  }

  while (node !== null) {
    if (queriedParents.indexOf(node) > -1) {
      return true;
    }

    node = node.parentNode;
  }

  return false;
}
Goes up the DOM tree and checks if element is child of another element.

@param child Child element
@param {Object|String} parent Parent element OR selector of the parent element.
                              If string provided, function returns `true` for the first occurrence of element with that class.
@returns {Boolean}