1

I am tryin to write a class that selects the dom elemented, by using XPath. So far, this is my code.
Problem is, node.id, makes the javascript fail.


What am I doing wrong? :/

var evaluator = new XPathEvaluator();

var result = evaluator.evaluate("//div", document.documentElement, null,
                             XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);                 

if (result) {
    alert(result)
    var node = result.iterateNext();
    while(node) {
            alert(node.id);
        node = node.iterateNext();
    }
}
3
  • It might be easier to use jQuery and CSS selectors. Commented Apr 21, 2011 at 22:21
  • Don't reinvent the wheel. Meet jQuery Commented Apr 21, 2011 at 22:28
  • 2
    Since when is easier a good enough argument to skip development? :) Anyway, I normally do use jQuery, I am just intrested in XPath at the moment and wanted to create a test Commented Apr 21, 2011 at 22:41

1 Answer 1

2

result.iterateNext, not node.iterateNext. Type in $x into Chrome/Safari Javascript Console for a full example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.