var xpath = "//a[./img]"; var as = document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null); var a = as.iterateNext(); while (a) { a = as.iterateNext(); console.log(a); }