2017-11-17 2 views
0

나는 다음을 수행하십시오DOM 찾을 수 없음 오류 혼란

$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); 
} 

(필자는 is_object 테스트 가능성이 불필요 실현,하지만 좌절에서 그것을 추가)과에 insertbefore에받을

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

하지 명확 -하지만 추측으로'$ anchor-> parentNode->에 insertbefore ($ 용기, $ anchor-> parentNode-> lastChild); ' –

+0

나는 그렇게 생각하지 않는다. 삽입은 $ anchor의 부모 중 마지막 자식이 아닌 $ anchor의 마지막 자식 앞에 위치해야합니다. 혼란은 insertBefore의 모든 요소가 존재한다는 것입니다 ... 그래서 나는 무엇이 발견되지 않았는지 알지 못합니다. – Ayen

+1

parentNode를 기반으로 insertBefore를 시도한 다음 현재 노드의 마지막 하위 노드 앞에 insert를 말하려고합니다. 그렇다면 - 현재 가지고있는 것에서'-> parentNode'를 제거하십시오. –

답변

1

parentNode를 기반으로 요소를 삽입하려고 시도했지만 lastChild 앞에 요소를 삽입하려고합니다. 이것은 하나의 세대입니다.

그래서 대신 ..

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

그것이 있어야 ...

$anchor->insertBefore($container, $anchor->lastChild); 
관련 문제