470,613 Members | 2,348 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

document.tagID vs document.all.tagID

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
Jul 20 '05 #1
1 3026
ym*@kicon.com (chirs) writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Brett Baisley | last post: by
12 posts views Thread by Kepler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.