code: function checkHierarchy ( elem, container ) {
  
          var elemIsContained;
  
          if ( elem.nodeType !== 1 ) throw new Error( "Invalid node: is not an element" );
  
          if ( $.isWindow( container ) ) {
              elemIsContained = elem.ownerDocument && container === ( elem.ownerDocument.defaultView || elem.ownerDocument.parentWindow );
          } else if ( container.nodeType === 9 ) {
              // We need a DOM element for this check, so we use the documentElement as a proxy if the container is a document.
              elemIsContained = $.contains( container.documentElement, elem );
          } else {
              elemIsContained = $.contains( container, elem );
          }
  
          if ( !elemIsContained ) throw new Error( "Invalid container: is not an ancestor of the element" );
  
      }
docs: Checks if the element is a descendant of the container, and throws an error otherwise. Also checks the type of
  the element (must indeed be an element node).
  
  For performance reasons, this check should *not* be run on every element in a set.
  
  @param {HTMLElement}                 elem
  @param {Window|Document|HTMLElement} container