[ACCEPTED]-Determine Parent Node Of DOMElement-dom

Accepted answer
Score: 27

DOMElement is a subclass of DOMNode, so it does have parent_node 7 property. Just use $domNode->parentNode; to 6 find the parent node.

In your example, the 5 parent node of $importnode is null, because 4 it has been imported into the document, and 3 therefore does not have a parent yet. You 2 need to attach it to another element before 1 it has a parent.

Score: 2

Replace parent_node() to parentNode


Score: 1

I'm not entirely sure how your code works, but 5 it seems like you have a small error in 4 your code.

On the line you posted in your 3 question you have $link->parent_node(), but in the answer with 2 the entire code snippet you have $link**s**->parent_node().

I don't 1 think the s should be there.

Also, I think you should use $link->parentNode, not $link->parent_node().

More Related questions