K
kelvSYC
I'm having a tough JavaScript problem. I'm fairly new to JavaScript,
and what I'm trying to do is to replace instances of a particular
string inside a particular element with another string. Here's what I
have so far:
var result = document.evaluate('//div[@class="code"]/code', document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (result) {
for (var i = 0, len = result.snapshotLength; i < len; i++) {
// use snapshotItem(i) to get nodes
var val = result.snapshotItem(i).nodeValue;
val = val.replace(/<-/gi, "â†");
result.snapshotItem(i).nodeValue = val;
}
}
The problem is that, even though I checked that my xpath works, the
result list is empty for some reason even though I know that it should
not be empty. Because of this, I haven't even checked to see that the
inside code works. Why is that?
and what I'm trying to do is to replace instances of a particular
string inside a particular element with another string. Here's what I
have so far:
var result = document.evaluate('//div[@class="code"]/code', document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (result) {
for (var i = 0, len = result.snapshotLength; i < len; i++) {
// use snapshotItem(i) to get nodes
var val = result.snapshotItem(i).nodeValue;
val = val.replace(/<-/gi, "â†");
result.snapshotItem(i).nodeValue = val;
}
}
The problem is that, even though I checked that my xpath works, the
result list is empty for some reason even though I know that it should
not be empty. Because of this, I haven't even checked to see that the
inside code works. Why is that?