code: function( ancestor, descendant, within )
      {
          var node = within ? descendant.parentNode : descendant;
          while( node )
          {
              if( node === ancestor )
                  return true;
              node = node.parentNode;
          }
          return false;
      }
docs: http://stackoverflow.com/questions/2234979/how-to-check-in-javascript-if-one-element-is-a-child-of-another