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

document.tagID vs document.all.tagID

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.