XMLHttpRequest, innerHTML

R

Razzbar

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.getElementById('somediv');
myDiv.innerHTML = xmlhttp.responseText;

.... 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,
 
R

Richard Cornford

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

It is a collection, not an array (similar in some respects, but
different in others).
Indeed they are in IE,

The - children - collection is a Microsoft proprietary feature that is
not universally supported.
but they aren't in Firefox.

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).

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

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

Richard.
 
R

Razzbar

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

I appreciate the clarification.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top