document.tagID vs document.all.tagID

C

chirs

Hi,

Is there a difference between document.tagID and document.all.tagID.
I've seen both like: document.myImage1.src = "nextImage2.jpg" and
document.all.hot1.style.color= ... where hot1 is in <span ID=hot1>.

Thanks.

Chris
 
L

Lasse Reichstein Nielsen

Is there a difference between document.tagID and document.all.tagID.

Yes, "all.". :p

Seriously, they are about equally wrong. Both work in IE. Neither work
in most other browsers (e.g., Mozilla/Netscape).
I've seen both like: document.myImage1.src = "nextImage2.jpg" and
document.all.hot1.style.color= ... where hot1 is in <span ID=hot1>.

Both exist. Neither should. For the first, use:
document.images['myImage1'].src = ...
or
document.images.myImage1.src = ...
or
document.getElementById("myImage1").src = ...

For the latter, use
document.getElementById("hot1").style.color = ...

All of these are specified in the W3C DOM.

Using the document.images collection is the safest method. It works
in all browsers since .. Netscape 3? 2? Since a long time ago.

The document.getElementById method requires a modern browser. The only
browsers that support document.all and not document.getElementById are
(as far as I know) IE 4 and WebTV. You can test for the existence of
getElementById first, and use it if it exists. If it doesn't exist,
check for document.all (IE4) or document.layers (Netscape 4) and use
what is available.

/L
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top