Skip to content

[DomCrawler] closest() and outerHtml() #18609

@rafis

Description

@rafis

Can you please add closest() to DomCrawler?

http://james.padolsey.com/jquery/#v=2.1.3&fn=jQuery.fn.closest

This is pseudo-code, not tested:

    public function closest($selector)
    {
        if (!count($this)) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }

        $node = $this->getNode(0);
        while ($node = $node->parentNode) {
            if (XML_ELEMENT_NODE === $node->nodeType) {
               $parent = $this->createSubCrawler($node)->filter($selector);
               if ($parent->count()) {
                  return $parent;
               }
            }
        }

        return null;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    DomCrawlerFeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy