How can one select specific sibling of a context node using jQuery?

不问归期 提交于 2021-02-04 18:10:48

问题


How can one select a specific sibling of a context node using jQuery? Specifically, given context node myContextNode select the sibling span with class myClass.

document.evaluate("../span[@class='myClass']",
    myContextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).
    singleNodeValue;

回答1:


You can use .siblings() with a selector, like this:

$(myContextNode).siblings("span.myClass")


来源:https://stackoverflow.com/questions/2569699/how-can-one-select-specific-sibling-of-a-context-node-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!