src/Nodes/NodeTrait.php
public function hasAncestorTag($tagName, $maxDepth = 3, callable $filterFn = null)
    {
        $depth = 0;
        $node = $this;

        while ($node->parentNode) {
            if ($maxDepth > 0 && $depth > $maxDepth) {
                return false;
            }

            if ($node->parentNode->nodeName === $tagName && (!$filterFn || $filterFn($node->parentNode))) {
                return true;
            }

            $node = $node->parentNode;
            $depth++;
        }

        return false;
    }
public function hasAncestorTag($tagName, $maxDepth = 3, callable $filterFn = null)
    {
        $depth = 0;
        $node = $this;

        while ($node->parentNode) {
            if ($maxDepth > 0 && $depth > $maxDepth) {
                return false;
            }

            if ($node->parentNode->nodeName === $tagName && (!$filterFn || $filterFn($node->parentNode))) {
                return true;
            }

            $node = $node->parentNode;
            $depth++;
        }

        return false;
    }
public function hasAncestorTag ( $ tagName , $ maxDepth = 3 , callable $ filterFn = null ) { $ depth = 0 ; $ node = $ this ; while ( $ node -> parentNode ) { if ( $ maxDepth > 0 && $ depth > $ maxDepth ) { return false ; } if ( $ node -> parentNode -> nodeName === $ tagName && ( ! $ filterFn || $ filterFn ( $ node -> parentNode ) ) ) { return true ; } $ node = $ node -> parentNode ; $ depth ++ ; } return false ; }
Check if a given node has one of its ancestor tag name matching the
provided one.

@param string $tagName
@param int $maxDepth
@param callable $filterFn

@return bool
Check if a given node has one of its ancestor tag name matching the provided one .