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

FluentDOM\Query::toggleClass()

FluentDOM\Query toggleClass(string|callable $class [ NULL|boolean $switch ]);

Adds the specified classes if the switch is TRUE, removes the specified classes if the switch is FALSE, toggles the specified classes if the switch is NULL.

Usage

$html = <<<HTML
<html>
  <head>
    <title>Examples: FluentDOM\Query::toggleClass()</title>
  </head>
  <body>
    <p class="blue">foo</p>
    <p class="blue highlight">bar</p>
  </body>
</html>
HTML;

echo FluentDOM($html)
  ->find('//p')
  ->toggleClass('highlight');

Output

<?xml version="1.0"?>
<html>
  <head>
    <title>Examples: FluentDOM\Query::toggleClass()</title>
  </head>
  <body>
    <p class="blue highlight">foo</p>
    <p class="blue">bar</p>
  </body>
</html>
Clone this wiki locally