XMLHttpRequest, innerHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Razzbar

    #1

    XMLHttpRequest, innerHTML

    I'm using the newly discoverd (to me :) XMLHttpRequest object to grab
    content for a page, then using innerHTML to insert the content, like...


    myDiv = document.getEle mentById('somed iv');
    myDiv.innerHTML = xmlhttp.respons eText;

    .... it works fine up to a point. The content I'm inserting is a series
    of elements, and so they should be accessable as the myDiv.children[]
    array. Indeed they are in IE, but they aren't in Firefox. If I try to
    get the myDiv.children. length value, I get a correct answer in IE, but
    FF gives me 'undefined'. I'd like to be able to access these nodes for
    various purposes.

    It seems like FF doesn't 'see' the innerHTML in the document tree (is
    that the correct term?).

    I haven't tried using appendChild to get the elements into their parent
    container, because it seems too inneficient. I'd have to take the
    responseText and split it into an array of elements, then iterate and
    insert. I'm hoping someone can come up with a way to "shake the tree"
    into knowing that myDiv has some children.

    ? TIA,

  • Richard Cornford

    #2
    Re: XMLHttpRequest, innerHTML

    Razzbar wrote:
    <snip>[color=blue]
    > ... . The content I'm inserting is a series
    > of elements, and so they should be accessable
    > as the myDiv.children[] array.[/color]

    It is a collection, not an array (similar in some respects, but
    different in others).
    [color=blue]
    > Indeed they are in IE,[/color]

    The - children - collection is a Microsoft proprietary feature that is
    not universally supported.
    [color=blue]
    > but they aren't in Firefox.[/color]

    Browsers implementing the W3C Core DOM standard, including
    Mozilla/Firefox and IE, implement a - childNodes - collection that
    performs a similar role to the - children - collector in IE, except that
    it is a collection of Nodes rather than Elements (Elements being a
    sub-set of Nodes).

    <snip>[color=blue]
    > It seems like FF doesn't 'see' the innerHTML in the
    > document tree (is that the correct term?).[/color]
    <snip>

    In HTML DOMs Firefox supports - innerHTML - dynamically, and
    corresponding nodes almost certainly form the containing element's -
    childNodes - collection.

    Richard.


    Comment

    • Razzbar

      #3
      Re: XMLHttpRequest, innerHTML

      Thanks, Richard. That clears things up. It works perfectly, and now I
      understand why I can't sort the 'array'.

      I appreciate the clarification.

      Comment

      Working...