Loading ...
Sorry, an error occurred while loading the content.

Re:NodeList returned includes "\n" as nodes

Expand Messages
  • Timothy Stone
    ... Hash: SHA1 From the W3Schools website, http://www.w3schools.com/Dom/prop_element_childnodes.asp ... Firefox, and most other browsers, will treat empty
    Message 1 of 3 , Aug 31, 2008
    • 0 Attachment
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      From the W3Schools website, http://www.w3schools.com/Dom/prop_element_childnodes.asp
      :

      "Firefox, and most other browsers, will treat empty white-spaces or
      new lines as text nodes, Internet Explorer will not. So, in the
      example above, the output will be different."

      Lovely.

      Regards,
      Tim
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.7 (Darwin)
      Comment: Ask me how you can start digitally signing your email!

      iD8DBQFIuqEaNsfkZJstizoRAjryAJ0ZGYgUFQZLgSNhM1P/U25w/jVa3ACfUuq3
      1QIUfiTAJoI28xNcDZ/ooo0=
      =t3rh
      -----END PGP SIGNATURE-----
    • Jeff Craig
      ... Not really. The Standard says that any whitespace between nodes is a own Text Node, and Firefox implements it this way. It s annoying, but it is the
      Message 2 of 3 , Sep 1 9:08 AM
      • 0 Attachment
        On Sat, 2008-08-30 at 13:07 -0400, Timothy Stone wrote:
        > When I query the document for various childNodes, I'm getting the
        > NodeList, plus "\n" as nodes, doubling the returned childNodes of a
        > particular element.
        >
        > The XHR is running on Firefox 3/Mac. It might be an implementation
        > bug.
        >
        > Any tips on this? Pointers already posted? My search of the list was
        > not as effective as I might have liked it. Right now I'm just looping
        > through the NodeList and testing its nodeType against "3" and
        > dropping
        > it. Any better way?

        Not really. The Standard says that any whitespace between nodes is a
        own Text Node, and Firefox implements it this way. It's annoying, but
        it is the standard, and you do have to develop against it. Because of
        the way the standard is developed, it does seem like you're expected to
        do a lot more of "getElementsByTagName" instead of iterating over
        childNodes, but if iterating childNodes is what makes sense in your
        problem space, what you're doing is reasonable.

        Jeff Craig
      Your message has been successfully submitted and would be delivered to recipients shortly.