Hi!
I use the following to get a html document into DOM:
$dom = new domDocument('1.0', 'utf-8');
$dom->loadHTML($html)
and then I add some new content to an element in the html:
$element = $dom->getElementById('mybox');
$f = $dom->createDocumentFragment();
$f->appendXML('<div id="newbox">foo</div>');
$element->appendChild($f);
But if I now want to manipulate the #newbox, I can't do it because I can't access it with getElementById()
. In order to do that I have to do the following (reloading with the new html):
$html = $dom->saveHTML();
$dom->loadHTML($html)
Which works fine, but when having to do this between every dom manipulation, it becomes expensive performance-wise.
Is there any better way to "refresh" the DOM so that it works with the newly added elements?
Thanks in advance! :)