vendredi 26 décembre 2014

XPath iteration Exception: "An attempt was made to use an object that is not, or is no longer, usable"


Slightly changed snippet from Mozilla's Introduction to using XPath in JavaScript is throwing exception.


[Exception... "An attempt was made to use an object that is not, or is no longer, usable" code: "11" nsresult: "0x8053000b (InvalidStateError)" location: "debugger eval code Line: 6"]


Code:



var headings = document.evaluate('//h2', document, null, XPathResult.ANY_TYPE, null );
var thisHeading = headings.iterateNext();

while (thisHeading) {
thisHeading.textContent = '\n';
thisHeading = headings.iterateNext();
}


The difference from original piece of code is that I'm altering elements - not just reading them.


Why do I see the exception and how to alter elements in iteration?





Aucun commentaire:

Enregistrer un commentaire