php8.5
Home/ Manual/ dom / tokenlist/ Dom\TokenList::add

Dom\TokenList::add

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Adds the given tokens to the list

Description

Dom\TokenList::add(string ...$tokens): void

Adds the given tokens to the list, but not any that were already present.

Parameters

tokens

The tokens to add.

Return Values

Void

Errors/Exceptions Errors

Examples

Dom\TokenList::add example

Adds two classes to a newly created paragraph element.

php
<?php
$dom = Dom\HTMLDocument::createEmpty();
$p = $dom->createElement('p');

$classList = $p->classList;
$classList->add('font-bold', 'important');

echo $dom->saveHtml($p);
?>

The above example will output:

output
<p class="font-bold important"></p>

Source: reference/dom/dom/tokenlist/add.xml · from the official PHP manual (php/doc-en)