public function closest($selector)
    {
        $result = $this->createChildInstance();

        if (isset($this->document) && $this->length > 0) {
            foreach ($this->nodes as $node) {
                $current = $node;

                while ($current instanceof \DOMElement) {
                    if (self::create($current)->is($selector)) {
                        $result->addDomNode($current);
                        break;
                    }
                    $current = $current->parentNode;
                }
            }
        }

        return $result;
    }
public function closest($selector)
    {
        $result = $this->createChildInstance();

        if (isset($this->document) && $this->length > 0) {
            foreach ($this->nodes as $node) {
                $current = $node;

                while ($current instanceof \DOMElement) {
                    if (self::create($current)->is($selector)) {
                        $result->addDomNode($current);
                        break;
                    }
                    $current = $current->parentNode;
                }
            }
        }

        return $result;
    }
public function closest ( $ selector ) { $ result = $ this -> createChildInstance ( ) ; if ( isset ( $ this -> document ) && $ this -> length > 0 ) { foreach ( $ this -> nodes as $ node ) { $ current = $ node ; while ( $ current instanceof \ DOMElement ) { if ( self :: create ( $ current ) -> is ( $ selector ) ) { $ result -> addDomNode ( $ current ) ; break ; } $ current = $ current -> parentNode ; } } } return $ result ; }
For each element in the set, get the first element that matches the selector
by testing the element itself and traversing up through its ancestors in the DOM tree.

@param string|self|callable|\DOMNodeList|\DOMNode $selector selector expression to match elements against

@return self
For each element in the set get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree .