php dom add class to element

Solutions on MaxInterview for php dom add class to element by the best coders in the world

showing results for - "php dom add class to element"
Jannik
20 Nov 2017
1$dom = new DOMDocument;
2$dom->loadHTML($html);
3$divs = $dom->getElementsByTagName('div');
4foreach ($divs as $div) {
5        $div->setAttribute('class', $div->getAttribute('class').' myclass');
6}
7$html = $dom->saveHTML();
8