-
-
Save codesorter2015/2135de00c05840a3ae8342f3e6827be3 to your computer and use it in GitHub Desktop.
getElementByXPath | Get DOM-Nodes by its XPath.
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
function ( | |
a, // the XPath | |
b // document-placeholder | |
) { | |
b = document; | |
return b.evaluate( | |
a, // xpathExpression | |
b, // contextNode | |
null, // namespaceResolver | |
9, // resultType | |
null // result | |
).singleNodeValue; // the first node | |
} |
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
function(a,b){b=document;return b.evaluate(a,b,null,9,null).singleNodeValue} |
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
{ | |
"name": "getElementByXPath", | |
"description": "Get DOM-Nodes by its XPath.", | |
"keywords": [ | |
"selector", | |
"xpath", | |
"path", | |
"node", | |
"dom" | |
] | |
} |
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
<!DOCTYPE html> | |
<title>getElementByXPath | Get DOM-Nodes by its XPath.</title> | |
<div>Expected value: <b>140byt.es</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
var getElementByXPath = function(a,b){b=document;return b.evaluate(a,b,null,9,null).singleNodeValue} | |
var path = '//html[1]/body[1]/div[1]/b[1]'; | |
document.getElementById('ret').innerHTML = getElementByXPath(path).innerHTML; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment