Created
October 30, 2009 12:09
-
-
Save fearphage/222294 to your computer and use it in GitHub Desktop.
IE-inspired convenience wrappers for document.evaluate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((typeof Node != 'undefined') && !document.selectNodes) { | |
Node.prototype.selectNodes = function(xpath, resolver) { | |
var contextNode = this.ownerDocument || this, result = [], i = 0, node | |
,nodes = contextNode.evaluate(xpath, contextNode, resolver || null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
while (node = nodes.snapshotItem(i++)) { | |
result.push(node); | |
} | |
return result; | |
}; | |
Node.prototype.selectSingleNode = function(xpath, resolver) { | |
return document.evaluate(xpath, this.ownerDocument || this, resolver || null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment