public function parent($selector = null) { $stack = array(); foreach ($this->elements as $node) { if ($node->parentNode && !$this->elementsContainsNode($node->parentNode, $stack)) { $stack[] = $node->parentNode; } } $this->elementsBackup = $this->elements; $this->elements = $stack; if ($selector) { $this->filter($selector, true); } return $this->newInstance(); }