Clive Backham meinte:
> My use of Javascript has until now been fairly limited, but I am now
> starting to look into using it to manipulate the DOM. To this end it
> appears that getElementById is a core function.
>
> However, I have been in the habit of setting CSS styles through the
> use of ID attributes, which means that many of my pages have multiple
> elements with the same ID, and of course this makes using
> getElementById rather difficult.
....and your documents invalid. Ids are supposed to be unique, hence
getElementById() vs. (for example) getElementsByName().
> It strikes me that perhaps using the ID attribute to select a style is
> deprecated, and I should switch to using the CLASS attribute instead.
> Would I be correct in thinking this, or is there some other more
> subtle issue that I have missed?
Your issues have nothing to do with JS. Perhaps the "subtle issue" is,
that you have never written a valid HTML document.
Anyway: ids aren't deprecated.
Apart from the "reusability" of classes with elements, the possibility
of ids to be used as anchors within pages, the lack of native DOM
methods to access elements specified class properties, the problems of
IE(6?) with Ids and element names, etc.
classes and id also have different priorities when combining styles.
Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum