On 16 Oct 2004 04:03:51 -0700, (e-mail address removed) (adam
buxton) wrote:
Ignore W3 Schools. If you're asking questions at this level, you need
to read the real specification.
http://www.w3.org/TR/html4/sgml/dtd.html
Learn how to read a DTD. The effort will repay itself.
CLASS and ID are common attributes for every tag yes or no?
They're certainly common, but not on _every_ element.
Strictly speaking, they're "coreattrs". Inside the DTD an entity is
declared called "coreattrs", which contains the set of attributes (
id, class, style, title ). These are intended for "common" use across
all elements (or nearly all). The element definitions then include
this entity "coreattrs", or else the entity "attrs" (which includes
coreattrs indirectly).
AFAIK all the HTML elements include this entity, from <body> down.
The elements used outside the body; <html>, <head>, <title> etc. are
the ones that don't include them.
Also "id" is an attribute, rather than "ID". Although HTML is
case-insensitive, XML and XHTML are case-sensitive, and you should
start paying attention to this.
"ID" is a basic SGML type within the DTD. It has constrained
behaviour; it must have a suitable format for a "name" and it must be
unique in the document. Because id is declared as being an ID, it
also behaves in this way. If you invent your own DTD though (maybe
for some new XML application), attributes called "id" aren't unique
identifiers unless you've also set their type.
if yes is it then ok to give every tag an ID and a CLASS?
Yes (except for that handful of elements)
the assignment stipulates the use of an averae of two attributes per
tag?
That's a crude rule of thumb, but it's a reminder to use plenty of
these attributes, wherever they're appropriate. You can apply the
same logic to the "title" attribute too.
Searching this newsgroup for "semantic" will show you many threads on
appropriate use of class and id.
In general, I use lots of class attributes for the purposes of CSS and
I use a few id attributes to assist with DHTML (client-side
JavaScript). I use very few id attributes for CSS purposes.
If there's the remotest likelihood that there could be more than one
element of a particular style on the page, then use class rather than
id. Even if you can't think why, just if it's not demonstrably wrong
to have more than one. In DHTML though, it's often necessary to
_uniquely_ identify an element, even if there are several very similar
ones.
Paste some of your code up for critique, if you want.