Skip to content
Merged
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
10 changes: 10 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ Access the value of the first node of the current selection::
// pass FALSE as the second argument to return the original text unchanged
$crawler->filterXPath('//body/p')->text('Default text content', false);

// innerText() is similar to text() but returns only the text that is
// the direct descendent of the current node, excluding any child nodes
$text = $crawler->filterXPath('//body/p')->innerText();
// if content is <p>Foo <span>Bar</span></p>
// innerText() returns 'Foo' and text() returns 'Foo Bar'

.. versionadded:: 5.4

The ``innerText()`` method was introduced in Symfony 5.4.

Access the attribute value of the first node of the current selection::

$class = $crawler->filterXPath('//body/p')->attr('class');
Expand Down