public function closest($selector, $strict = false)
    {
        $node = $this;

        while (true) {
            $parent = $node->parent();

            if ($parent === null || $parent instanceof Document) {
                return null;
            }

            if ($parent->matches($selector, $strict)) {
                return $parent;
            }

            $node = $parent;
        }
    }
public function closest($selector, $strict = false)
    {
        $node = $this;

        while (true) {
            $parent = $node->parent();

            if ($parent === null || $parent instanceof Document) {
                return null;
            }

            if ($parent->matches($selector, $strict)) {
                return $parent;
            }

            $node = $parent;
        }
    }
public function closest ( $ selector , $ strict = false ) { $ node = $ this ; while ( true ) { $ parent = $ node -> parent ( ) ; if ( $ parent === null || $ parent instanceof Document ) { return null ; } if ( $ parent -> matches ( $ selector , $ strict ) ) { return $ parent ; } $ node = $ parent ; } }
Returns first parent node matches passed selector.

@param string $selector
@param bool $strict

@return \DiDom\Element|null
Returns first parent node matches passed selector .