Code snippets: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
m (Redirected page to Category:Coding Tips)
 
(166 intermediate revisions by 41 users not shown)
Line 1: Line 1:
= xpath helper =
#REDIRECT [[:Category:Coding Tips]]
 
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 <code>p</code> against the context node <code>context</code> (or the document, if not provided).
Return the results as an array.

Latest revision as of 19:09, 4 February 2010