Laurie Harper wrote:
Why do you say that's a bad practice? It's actually both supported and
recommended; in fact, the 'name' attribute is deprecated in favour of
the 'id' attribute so 'id' is the only way to target CSS to a particular
page element rather than an entire display class.
...
OK, you could use class="something-I-made-sure-is-unique" instead of
using id, but why do that and loose the ability to have uniqueness
checked by validation?
Exactly. class is what should be used. Well, ok, if I'm being fair,
this is a debatable point, I can't point to any document somewhere that
says there is a right and wrong answer. It is a bad practice to me
though based on my experience :)
The reason for this, in my mind, is that an ID attribute must be unique
across a document so that you can uniquely address any individual
element on the page by name. This makes DOM manipulation much easier,
and frankly more like the back end where you are either addressing a
specific object instance by name, or accessing the member of a
collection. But that's maybe getting a tad off track I suppose :) ...
By separating the CSS class an element uses from the ID you access it
with you gain flexibility in being able to manipulate individual objects
as well as change the stylesheet more precisely. More importantly
perhaps, it eliminates duplication of style definitions.
For example, imagine a situation where you have a series of textboxes,
and you want to apply a style to each and also be able to address each
individually via scripting...
<input type="text" id="css1">
<input type="text" id="css2">
<input type="text" id="css3">
Ok, so I can certainly address each individually by name. But what does
the stylesheet look like? It would have three styles defined that are
all duplicate. Kind of inefficient. But, if you do:
<input type="text" id="tb1" class="css1">
<input type="text" id="tb2" class="css1">
<input type="text" id="tb3" class="css1">
Now, you can still address each individually, and now they all use the
same style definition. Duplication removed.
Actually, I did find one reference that seems relevant:
http://www.htmlhelp.com/reference/css/style-html.html#id
Specifically, the first sentence of the last paragraph:
"The use of ID is appropriate when a style only needs to be applied once
in any document."
That's another way of saying what I was trying to say above :)
But, even putting all that aside... assigning a CSS class to an element
with the ID attribute just seems wrong semantically... ID has a pretty
specific meaning, it's a unique identifier. class also has a fairly
specific meaning in this context, it's defining the supertype of an
element (in essence), and doing it otherwise seems like fighting logic :)
I'm not sure about your validation point though... could you clarify
that? You may well be pointing something out I've never considered.
Not trying to go on the attack or anything here :-) Just curious where
this is coming from...
Sure, no problem at all. Like I said, I can't point to any official
spec or something that says "this is the right way to do it", but I know
what I have my people do and I know what has served me best over the
years :) I have no doubt you and others have contrary experiences that
are just as valid.
Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]