Code snippets

From GreaseSpot Wiki
Revision as of 15:20, 15 March 2007 by Arantius (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

xpath helper

function xpath(p, context) {
    if (!context) context=document;
    var arr=[];
    var xpr=document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for(i=0;item=xpr.snapshotItem(i);i++){ arr.push(item); }
    return arr;

Run a particular xpath expression p against the context node context (or the document, if not provided). Return the results as an array.