Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.37 KB

addclass-and-removeclass.md

File metadata and controls

55 lines (41 loc) · 1.37 KB

addClass and removeClass

<< Previous                                                              Next >>

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.

Syntax: addClass and removeClass

$doc->query("[selector]")->addClass("[className]");
$doc->query("[selector]")->removeClass("[className]");

$html

<h1>Give me a title class</h1>
<h2 class="title">Hey! My class should be "subtitle"!</h2>

Php

<?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();

Output

<h1 class="title">Give me a title class</h1>
<h2 class="subtitle">Hey! My class should be "subtitle"!</h2>

Example test code snippet

Click here to go to example test.