Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] document the ancestors() method #14774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ Get the same level nodes after or before the current selection::
$crawler->filter('body > p')->nextAll();
$crawler->filter('body > p')->previousAll();

Get all the child or parent nodes::
Get all the child or ancestor nodes::

$crawler->filter('body')->children();
$crawler->filter('body > p')->parents();
$crawler->filter('body > p')->ancestors();

.. versionadded:: 5.3

The ``ancestors()`` method was introduced in Symfony 5.3.

Get all the direct child nodes matching a CSS selector::

Expand Down
8 changes: 4 additions & 4 deletions testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ selects the last one on the page, and then selects its immediate parent element:

$newCrawler = $crawler->filter('input[type=submit]')
->last()
->parents()
->ancestors()
->first()
;

Expand All @@ -735,8 +735,8 @@ Many other methods are also available:
All following siblings.
``previousAll()``
All preceding siblings.
``parents()``
Returns the parent nodes.
``ancestors()``
Returns the ancestor nodes.
``children()``
Returns children nodes.
``reduce($lambda)``
Expand Down Expand Up @@ -766,7 +766,7 @@ Extracting Information
The Crawler can extract information from the nodes::

use Symfony\Component\DomCrawler\Crawler;

// returns the attribute value for the first node
$crawler->attr('class');

Expand Down