473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
3 6730
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
9
by: Arash Dejkam | last post by:
Hi All, Is it possible to write on an <OBJECT type="text/html"> using document.write() from within the html containing that tag the way we write on a popup window? I couldn't do that after a lot...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
1
by: finizaini | last post by:
I'm receiving an "Object Expected" Error (Line:309, Char:0). I'm confused as to what is happening.Also, I can't run this code using other browser such as Fire Fox. Thispage only can view using IE....
6
by: cleary1981 | last post by:
I have adapted code from http://dunnbypaul.net/js_mouse/ I want to use a button to create new draggable divs but i keep getting error "is null or not an object" heres the code <html> <head>...
2
by: bips2008 | last post by:
The code seems to work fine in other browser but in IE it throws this error. This is very urgent for me and any help would be greatly appreciated For your convienence i have posted the code for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.