[Javascript] how to refer to (x)html elements

David Lovering dlovering at gazos.com
Thu Nov 13 16:28:26 CST 2003


Let's put this to bed.  The original intention of CSS was to develop
portable ("reuseable") style elements which could be applied by handle to
multiple objects.  Seemingly contrary to this function, the use of "ID"
(which as Hassan pointed out is consistantly defined within both HTML and
CSS2) is intended to characterize a single instance.  However, as a large
number of FrontPage-generated web pages will readily demonstrate, MS often
uses "ID" in what both I and Hassan agree is a contrary and incorrect
fashion -- namely to port a single style definition to multiple real objects
on the page.  [Strangely enough, they also use "CLASS" ].

The "correct" way is to use a CLASS declaration, as follows --

<style type="text/CSS">
<!--
    .myStyle { font-style: italic; color: red; }  // notice the lead
'period'
// -->
</style>
.....

<p class="myStyle">Blah-blah-blah</p>
<p class="myStyle">This is a second paragraph using the same style.</p>
<p class="myStyle">This is a third paragraph using the same style.</p>

There are a couple of variations, depending on whether ".myStyle" is to be
used across a wide assortment of style elements, or just one particular
category of style elements.

This use of the CLASS declaration is not only correct, but absolutely
consistant throughout HTML, CSS, JavaScript, and a number of related
languages, and is close enough to the way XML works that no one is likely to
pass blood over the issue.  Most importantly, it doesn't tempt you into
using the same label for a style element and later for an object identifier
when you REALLY don't want the style to apply to it.

In other words, please don't reuse the same ID on different objects within
the same page -- otherwise your friends will all laugh at you, and your code
will be both fragile and non-portable.  [Even for radio buttons it is
unwise!]  The fact that IE will even tolerate this is a black mark against
their parsing engine.

-- Dave Lovering

P.S:  Hassan is correct, even if a bunch of us idiots insist on doing things
in a contrary fashion


----- Original Message ----- 
From: "Hassan Schroeder" <hassan at webtuitive.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, November 13, 2003 11:39 AM
Subject: Re: [Javascript] how to refer to (x)html elements


> David Lovering wrote:
>
> > The use of ID is again employed (as I suggested) as a CSS2 standard.  I
> > believe the w3 standards group is the same one that backed the HTML
standard
> > (and by extension the JavaScript usage of the id header).  I don't
believe
> > they are in the practice of promoting nonsense, although I could be
> > mistaken.
>
> I've no idea what that has to do with an ID being unique within
> a document. As the page you referenced says,
>
>    "The ID attribute of a document language allows authors to
>     assign an identifier to one element instance in the document
>     tree."
>
> Nowhere does it suggest that there's a "CSS ID" that's different
> from "an HTML ID" or "a JavaScript ID"...
>
> > Now for the peace offering -- I AGREE with you; the only meaningful role
for
> > "id" is as a one-to-one and onto identification for DOM objects.  The
pity
> > is that the CSS folks didn't pick something other than "ID" as the
handle to
> > hang all this other stuff off of.
>
> what "other stuff"?? An "id" represents a unique object within the
> document. It's irrelevant whether you want to style that object or
> move it or add event handlers to it. Whatever you want to do with
> it, the "id" gives you a handle.
>
> Why the heck would anyone want to have to address the same object
> two different ways?
>
> -- 
> Hassan Schroeder ----------------------------- hassan at webtuitive.com
> Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com
>
>                            dream.  code.
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>





More information about the Javascript mailing list