Skip to content
Thomas Weinert edited this page Jul 29, 2014 · 4 revisions

FluentDOM\Nodes::find()

FluentDOM\Nodes find(string|DOMNode|DOMNodelist $selector[, bool $useDocumentContext = FALSE]);

Searches for descendant elements that match the specified expression.

If the $selector is an node or a list of nodes all descendants that match that node/node list are returned.

Usage

$xml = <<<'XML'
<html>
  <head>
    <title>Examples: FluentDOM\Query::find()</title>
  </head>
  <body>
    <p><span>Hello</span>, how are you?</p>
    <p>Me? I am <span>good</span>.</p>
  </body>
</html>
XML;

echo FluentDOM($xml)
  ->find('//p')
  ->find('span')
  ->addClass('red');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::find()</title>
  </head>
  <body>
    <p><span class="red">Hello</span>, how are you?</p>
    <p>Me? I am <span class="red">good</span>.</p>
  </body>
</html>
Clone this wiki locally