Query ToggleClass - ThomasWeinert/FluentDOM GitHub Wiki
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.
$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');
<?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>