Let\'s say I have following HTML:
X1
You could use xpath:
document.evaluate('following::*[@class="x"], elt, null, XPathResult.ANY_TYPE, null);
or you could use a walker:
var walker = document.createTreeWalker(elt, NodeFilter.SHOW_ELEMENT, function(node) {
return node.classList.has('x');
});
while (walker.nextNode) {
do_something_with(walker.currentNode);
}