Iterate over framesets with XPath expression in JavaScript?

Posted by Derek Mahar on Stack Overflow See other posts from Stack Overflow or by Derek Mahar
Published on 2010-05-07T21:09:02Z Indexed on 2010/05/09 22:58 UTC
Read the original article Hit count: 438

Filed under:
|
|

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]);
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom