Iterate over framesets with XPath expression in JavaScript?
- by Derek Mahar
Why does the following JavaScript, when run in Firefox 3.6.3, delete all FRAMESET elements in a document, but the similar script that instead uses an XPath expression to select the FRAMESET elements, does not? Is document.evaluate() simply unable to match FRAMESET elements? Is there an error in the XPath expression? Is there some other error?
Select all FRAMESET elements using method document.getElementsByTagName() (succeeds):
var framesets = document.getElementsByTagName('frameset');
for (var i = 0; i < framesets.length; i++) {
framesets[i].parentNode.removeChild(framesets[i]);
}
Select all FRAMESET elements using an XPath expression (fails):
var framesets = document.evaluate("//frameset", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < framesets.length; i++) {
framesets[i].parentNode.removeChild(framesets[i]);
}