function Crawler::ancestors
Returns the ancestors of the current selection.
Throws
\InvalidArgumentException When the current node is empty
File
-
vendor/
symfony/ dom-crawler/ Crawler.php, line 459
Class
- Crawler
- Crawler eases navigation of a list of \DOMNode objects.
Namespace
Symfony\Component\DomCrawlerCode
public function ancestors() : static {
if (!$this->nodes) {
throw new \InvalidArgumentException('The current node list is empty.');
}
$node = $this->getNode(0);
$nodes = [];
while ($node = $node->parentNode) {
if (\XML_ELEMENT_NODE === $node->nodeType) {
$nodes[] = $node;
}
}
return $this->createSubCrawler($nodes);
}