Reputation: 7599
I'm trying to apply 2 classes to an element like this:
$div->setAttribute('class', 'txt found');
unfortunately it won't work as i'm getting the following markup:
<div found="" class="txt">
I've also tried $div->class = "txt found";
which had same result.
Any ideas how to fix this?
Upvotes: 0
Views: 482
Reputation: 15550
Could you please try following;
$div->className = "txt found";
Updated:
<?php
$divHtml = "<div></div>";
$dom = new DOMDocument();
$dom->loadHTML($divHtml);
$allElements = $dom->getElementsByTagName('div');
$divElement = $allElements->item(0);
$divElement->setAttribute("class", "txt found");
echo $dom->saveHTML();
?>
I tried to reproduce your case and finally it worked.You can test it.If you send more code we can modify it inorder to work
Upvotes: 1