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

FluentDOM\Query::siblings()

FluentDOM\Query siblings([ $selector = NULL ])

Get a set of elements containing all of the unique siblings of each of the matched set of elements.

Usage

$html = <<<HTML
<html>
  <head>
    <title>Examples: FluentDOM\Query::siblings()</title>
  </head>
  <body>
    <ul>
      <li>One</li>
      <li>Two</li>
      <li class="hilite">Three</li>
      <li>Four</li>
    </ul>
    <ul>
      <li>Five</li>
      <li>Six</li>
      <li>Seven</li>
    </ul>
    <ul>
      <li>Eight</li>
      <li class="hilite">Nine</li>
      <li>Ten</li>
      <li class="hilite">Eleven</li>
    </ul>
    <p>Unique siblings: <b> </b></p>
  </body>
</html>
HTML;

echo FluentDOM($html)
  ->find('//li[@class = "hilite"]')
  ->siblings()
  ->addClass('before');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::siblings()</title>
  </head>
  <body>
    <ul>
      <li class="before">One</li>
      <li class="before">Two</li>
      <li class="hilite">Three</li>
      <li class="before">Four</li>
    </ul>
    <ul>
      <li>Five</li>
      <li>Six</li>
      <li>Seven</li>
    </ul>
    <ul>
      <li class="before">Eight</li>
      <li class="hilite before">Nine</li>
      <li class="before">Ten</li>
      <li class="hilite before">Eleven</li>
    </ul>
    <p>Unique siblings: <b> </b></p>
  </body>
</html>
Clone this wiki locally