Answer the question
In order to leave comments, you need to log in
How to add an attribute with a value to a tag using the DOMDocument class?
Tried using setAttribute method - doesn't help
$dom->loadHtml($html);
$h2s = $dom->getElementsByTagName('h2');
foreach ($h2s as $h2) {
$h2->setAttribute('id', 5);
}
Answer the question
In order to leave comments, you need to log in
Where do you expect to see it?
The method adds an attribute to the object, from which you then need to build html again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question