0

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?

Sue Maurizio
  • 662
  • 7
  • 17
  • 2
    Firefox appears to support the `innerText` property now, though it came pretty late to the party: ['innerText' works in IE, but not in Firefox](http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox). I'm not sure whether that's related to your problem. – apsillers Mar 09 '15 at 13:40
  • 1
    use elm.children instead of elm.childNodes unless you really do want whitespace, comment nodes, etc. – dandavis Mar 09 '15 at 13:43

1 Answers1

0

Looks like Firefox 36.0.1 is not completely ok with property innerText, after all (thanks apsillers!). I replaced it with textContent and now the script works in Firefox, Chrome, IE and Safari.

Sue Maurizio
  • 662
  • 7
  • 17