且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取父节点及其子节点,其中的子节点具有特定的文本

更新时间:2022-10-18 11:42:18

获得该项目后,只需获取其 - > parentNode 属性。


I am trying to retrieve a parent node and it's child, where the child has a certain text.

this is my html:

<bod>
    <div>
         <span>something</span>
    </div>
</body>

i am using the following to catch the child :

 $the_child = $xpath->query('(//*[text()[contains(., "something")]])[1]');

but how do i also catch his first parent ?

Once you have the item, just get its ->parentNode property.