Skip to content
Thomas Weinert edited this page Jul 31, 2014 · 1 revision

FluentDOM\Query::prevAll()

FluentDOM\Query prevAll([ string $selector = NULL ])

Find all sibling elements before the current element.

Usage

$html = <<<HTML
<html>
  <head>
    <title>Examples: FluentDOM\Query::prevAll()</title>
  </head>
  <body>
    <div><span>has child</span></div>
    <div id="start"> </div>
    <div> </div>
    <div><span>has child</span></div>
    <div class="here"><span>has child</span></div>
    <div><span>has child</span></div>
    <div class="here"> </div>
    <div> </div>
    <p><button>Go to Prev</button></p>
  </body>
</html>
HTML;

echo FluentDOM($html)
  ->find('//div[@id = "start"]')
  ->prevAll()
  ->addClass('before');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::prevAll()</title>
  </head>
  <body>
    <div class="before"><span>has child</span></div>
    <div id="start"> </div>
    <div> </div>
    <div><span>has child</span></div>
    <div class="here"><span>has child</span></div>
    <div><span>has child</span></div>
    <div class="here"> </div>
    <div> </div>
    <p><button>Go to Prev</button></p>
  </body>
</html>
Clone this wiki locally