How would this code be refactored to use jQuery?
function emleProcessOnLoad(aThis) {
var result = document.evaluate("//span[@class='emleOnLoad']",
aThis.document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var jj=0; jj<result.snapshotLength; jj++){
eval("var emleThis=result.snapshotItem(jj);" + result.snapshotItem(jj).textContent);
}
}
There appears to be four issues for jQuery to address:
- Context:
aThis.document
- Selection:
//span[@class='emleOnLoad']
- Iteration:
for (var jj=0; jj<result.snapshotLength; jj++)
- Value:
.textContent
The code is a fragment from Emle - Electronic Mathematics Laboratory Equipment JavaScript file emle_lab.js.
The .evaluate()
function grabs all of the <span>
tags which have class emleOnLoad
. The resulting text content contains an expression fragment such as:
emleHandleInput(emleThis.parentNode.parentNode,"EMLE_CET_PROPER_FRACTION");
which is appended to:
var emleThis=result.snapshotItem(jj);
and then is executed for each item found by the .evaluate()
function.