By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

How do I get the object type from document.all?

P: n/a
Hi,

Please, can somebody tell me how to do this?

I am using document.all in a script to retrieve the elements in a
document which have a certain id. document.all returns a reference to
an element or an array. If the id is unique within the document then
document.all returns a reference to the element. If there is more than
one element with the same id then an array is returned.

Is there some way of determining what type of object is returned? I can
look at the properties of the object but is there some other way of
finding out the object type?

Thanks in advance.

sean

Aug 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
seans wrote:
Hi,

Please, can somebody tell me how to do this?

I am using document.all in a script to retrieve the elements in a
document which have a certain id. document.all returns a reference to
an element or an array. If the id is unique within the document then
document.all returns a reference to the element. If there is more than
one element with the same id then an array is returned.


Having multiple instances of the same ID will make your HTML invalid.
ID's must be unique within a page.

And unless your page is for IE only, use DOM compliant methods and
feature detection:

<URL:http://www.jibbering.com/faq/#FAQ4_15>

[...]

--
Rob
Aug 14 '05 #2

P: n/a
Hi Rob.

Thanks for your help. This seems to work.

if (document.all['elementID'].len*gth) { // we have an array

}
else { // we have a single object

}

cheers,

sean

Aug 14 '05 #3

P: n/a
On 14/08/2005 13:06, seans wrote:

[snip]
if (document.all['elementID'].len*gth) { // we have an array

}
else { // we have a single object

}


Except where the element has its own length property, as in the FORM and
SELECT elements. Perhaps a better test is to check for the tags method,
which should only exist on all-based collections.

Still, the all collection should, in my opinion, only be used in two
circumstances:

1) When writing code for IE 4.
2) When fixing-up the getElementsByTagName method in IE 5.x and
earlier, when its argument is an asterisk ('*').

In other circumstances, it should be abandoned in favour of the
getElementById method.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.