Reputation: 198
there is a xml, http://kquery.veryos.com/w3.xml
open chrome developer tool, and run 'document.querySelectorAll("div ~ div")' in console, returns 4292 elements.
document.querySelectorAll('div ~ div')
NodeList[4292]
but using the XPath experssion equals to css selector 'div ~ div', select nothing, no element returns.
result = document.evaluate('//div/following-sibling::div',document,null,XPathResult.ANY_TYPE);
result.iterateNext(); //null
result = document.evaluate('//div[preceding-sibling::div]',document,null,XPathResult.ANY_TYPE);
result.iterateNext(); //null
r=document.evaluate('//div/following-sibling::*', document, null, XPathResult.ANY_TYPE,null);
r.iterateNext(); //element
any problems of the experssion '//div/following-sibling::div' or '//div[preceding-sibling::div]' ?
anybody helps ?
Upvotes: 0
Views: 1118
Reputation: 242208
There is only one div
in the document. Therefore, searching for a div
preceded by another div
returns nothing.
Upvotes: 0