document.tagID vs document.all.tagID

Discussion in 'Javascript' started by chirs, Dec 1, 2003.

  1. chirs

    chirs Guest

    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
    chirs, Dec 1, 2003
    #1
    1. Advertising

  2. (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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Dec 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Ley
    Replies:
    3
    Views:
    196
  2. wk
    Replies:
    5
    Views:
    161
    Dietmar Meier
    Apr 22, 2005
  3. Martin
    Replies:
    3
    Views:
    135
  4. yawnmoth

    document.all vs. document.layers

    yawnmoth, Dec 24, 2005, in forum: Javascript
    Replies:
    2
    Views:
    82
    Michael Winter
    Dec 24, 2005
  5. Replies:
    4
    Views:
    153
    Jonas Raoni
    Nov 21, 2006
Loading...

Share This Page