JAyenGreen
JAyenGreen

Reputation: 1435

DOM Not Found Error Confusion

I do the following:

$container = $element->ownerDocument->createNode($tag);
if ( $anchor->hasChildNodes() && 
     is_object($anchor->lastChild) && 
     $anchor->lastChild->nodeName == 'span' && 
     $container->nodeName == 'span' ) {

        $anchor->parentNode->insertBefore($container, $anchor->lastChild);
}

(I realize that the is_object test is likely superfluous, but added it out of frustration) and on the insertBefore receive

Fatal error: Uncaught exception 'DOMException' with message 'Not Found Error' 

Upvotes: 0

Views: 430

Answers (1)

Nigel Ren
Nigel Ren

Reputation: 57131

Your attempting to insert an element based on the parentNode, but inserting it before the lastChild. This is one generation apart.

So instead of..

 $anchor->parentNode->insertBefore($container, $anchor->lastChild);

it should be...

 $anchor->insertBefore($container, $anchor->lastChild);

Upvotes: 1

Related Questions