C
Csaba Gabor
In Firefox 1.5 (this question is Mozilla specific as I am using
greasemonkey) I would like to be able to use document.evaluate to
return the first TD entry that shows ^\s*MySearchText\s*$. As I
understand it, xpath doesn't yet have regular expressions so I thought
to do:
function findNode (srch) {
var node;
var expr="//td[contains(@innerHTML,'"+srch+"')]";
var RE = new RegExp("\\s*" + srch + "\\s*$");
var xpathResult = document.evaluate(expr, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < xpathResult.snapshotLength; i++) {
node = xpathResult.snapshotItem(i);
if (node.innerHTML.match(RE)) return (node); // node found
}
return null; // node was not found
}
This always returns null though. Specifically,
xpathResult.snapshotLength is always 0 since document.evaluate
evidently doesn't like that @innerHTML. Short of looping through all
TDs, is there another approach someone might suggest?
Thanks,
Csaba Gabor from Vienna
greasemonkey) I would like to be able to use document.evaluate to
return the first TD entry that shows ^\s*MySearchText\s*$. As I
understand it, xpath doesn't yet have regular expressions so I thought
to do:
function findNode (srch) {
var node;
var expr="//td[contains(@innerHTML,'"+srch+"')]";
var RE = new RegExp("\\s*" + srch + "\\s*$");
var xpathResult = document.evaluate(expr, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < xpathResult.snapshotLength; i++) {
node = xpathResult.snapshotItem(i);
if (node.innerHTML.match(RE)) return (node); // node found
}
return null; // node was not found
}
This always returns null though. Specifically,
xpathResult.snapshotLength is always 0 since document.evaluate
evidently doesn't like that @innerHTML. Short of looping through all
TDs, is there another approach someone might suggest?
Thanks,
Csaba Gabor from Vienna