The addClass()
and removeClass()
methods add or remove one or more class names to the selected elements.
Tip: To add more than one class, separate the class names with spaces.
$doc->query("[selector]")->addClass("[className]");
$doc->query("[selector]")->removeClass("[className]");
<h1>Give me a title class</h1>
<h2 class="title">Hey! My class should be "subtitle"!</h2>
<?php
include "../src/webparser.php";
$doc = new WebParser();
$doc->loadHTML($html);
$doc->Q("h1")->addClass("title");
$doc->Q("h2")->removeClass("title");
$doc->Q("h2")->addClass("subtitle");
$doc->output();
<h1 class="title">Give me a title class</h1>
<h2 class="subtitle">Hey! My class should be "subtitle"!</h2>
Click here to go to example test.