I'm writing a small script to parse a HTML page with the help of jQuery; while my script works as I expect in Chrome, IE and Safari, I can't explain its behavior in Firefox (version 36.0.1). Here it is:
$.ajax({
url: 'myURL.aspx',
async: false,
success: function (data) {
html = $.parseHTML(data, document, true);
$.each(html, function (i, el) {
if (el.nodeName === "FORM") {
$.each(el.childNodes, function (j, n) {
if (typeof n != "undefined") {
if (n.nodeName === "SCRIPT") {
if (typeof n.innerText != "undefined") {
if (n.innerText.indexOf("...") != -1) {
if (n.nodeType == 1) {
$("body").append(n);
}
}
}
}
}
});
}
});
}
});
The problem is, I set a breakpoint on the line where I'm calling append
and, if I inspect the properties of n
the first time the debugger breaks, I see that n.nodeName
is not SCRIPT
, n.innerText
is undefined
and n.nodeType
is 3
. Is there something I'm completely misunderstanding?