QueryPath\DOMQuery::parent PHP Method

parent() public method

If a selector is passed, this will return the nearest matching parent for each element in the DOMQuery.
See also: children()
See also: siblings()
See also: parents()
public parent ( string $selector = null )
$selector string A valid CSS3 selector.
    public function parent($selector = null)
    {
        $found = new \SplObjectStorage();
        foreach ($this->matches as $m) {
            while ($m->parentNode->nodeType !== XML_DOCUMENT_NODE) {
                $m = $m->parentNode;
                // Is there any case where parent node is not an element?
                if ($m->nodeType === XML_ELEMENT_NODE) {
                    if (!empty($selector)) {
                        if (QueryPath::with($m, null, $this->options)->is($selector) > 0) {
                            $found->attach($m);
                            break;
                        }
                    } else {
                        $found->attach($m);
                        break;
                    }
                }
            }
        }
        return $this->inst($found, null, $this->options);
    }