You are here

public function Crawler::parents in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::parents()

Returns the parents nodes of the current selection.

Return value

Crawler A Crawler instance with the parents nodes of the current selection

Throws

\InvalidArgumentException When current node is empty

File

vendor/symfony/dom-crawler/Crawler.php, line 472

Class

Crawler
Crawler eases navigation of a list of \DOMElement objects.

Namespace

Symfony\Component\DomCrawler

Code

public function parents() {
  if (!count($this)) {
    throw new \InvalidArgumentException('The current node list is empty.');
  }
  $node = $this
    ->getNode(0);
  $nodes = array();
  while ($node = $node->parentNode) {
    if (1 === $node->nodeType) {
      $nodes[] = $node;
    }
  }
  return $this
    ->createSubCrawler($nodes);
}