Connecting Tech Pros Worldwide Help | Site Map

ID selectors: duplicated selectors

Sue Sims
Guest
 
Posts: n/a
#1: Jul 20 '05
From <URL: http://www.w3.org/TR/CSS21/selector.html#id-selectors >

I find the following text:
"What makes attributes of type ID special is that no two such attributes
can have the same value;..."

In the second example, I find the rule:

*#z98y { letter-spacing: 0.3em }

It seems to me that using the universal selector in this example is wrong,
given the text above which includes "no two such attributes can have the
same value".

Given that all of the UAs to which I have access treat all duplicated IDs
in the above example exactly the same, I was just curious about what a UA
is *supposed* to do.

Sue
Eric Bohlman
Guest
 
Posts: n/a
#2: Jul 20 '05

re: ID selectors: duplicated selectors


Sue Sims <sue@css.nu> wrote in news:opryskt9ndv3x9px@netnews.att.net:
[color=blue]
> From <URL: http://www.w3.org/TR/CSS21/selector.html#id-selectors >
>
> I find the following text:
> "What makes attributes of type ID special is that no two such
> attributes can have the same value;..."
>
> In the second example, I find the rule:
>
> *#z98y { letter-spacing: 0.3em }
>
> It seems to me that using the universal selector in this example is
> wrong, given the text above which includes "no two such attributes can
> have the same value".[/color]

Actually, the universal selector there simply means that it doesn't matter
what element *type* has the particular ID; it could be a <p>, or a <div>,
or what have you. The selector refers to any element with that ID. The
fact that only one *element* in a document can have a particular idea
doesn't imply that only one *element type* can have it. It could be an
element of any type; there just can't be two or more such elements in the
same document.
Sue Sims
Guest
 
Posts: n/a
#3: Jul 20 '05

re: ID selectors: duplicated selectors


On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <ebohlman@earthlink.net> wrote:
[color=blue]
> Actually, the universal selector there simply means that it doesn't
> matter
> what element *type* has the particular ID; it could be a <p>, or a <div>,
> or what have you. The selector refers to any element with that ID. The
> fact that only one *element* in a document can have a particular idea
> doesn't imply that only one *element type* can have it. It could be an
> element of any type; there just can't be two or more such elements in the
> same document.[/color]

It seemed to me that using the universal selector in that test case would
encourage re-use of the ID, which is not "allowed".

At any rate, I'm wondering whether any UA does not allow this re-use? I've
put up a TC here <URL: http://css.nu/examples/1692.html > which re-uses
the markup in the W3C example on duplicated elements, and would appreciate
input. Is this how the UA is supposed to render the markup? If so, why?

Sue "trying to clean out old bugs from the Opera bug tracking system" Sims
Anne van Kesteren
Guest
 
Posts: n/a
#4: Jul 20 '05

re: ID selectors: duplicated selectors


Sue Sims wrote:[color=blue]
> On 17 Nov 2003 17:28:19 GMT, Eric Bohlman <ebohlman@earthlink.net> wrote:
>[color=green]
>> Actually, the universal selector there simply means that it doesn't
>> matter
>> what element *type* has the particular ID; it could be a <p>, or a <div>,
>> or what have you. The selector refers to any element with that ID. The
>> fact that only one *element* in a document can have a particular idea
>> doesn't imply that only one *element type* can have it. It could be an
>> element of any type; there just can't be two or more such elements in the
>> same document.[/color]
>
>
> It seemed to me that using the universal selector in that test case
> would encourage re-use of the ID, which is not "allowed".
>
> At any rate, I'm wondering whether any UA does not allow this re-use?
> I've put up a TC here <URL: http://css.nu/examples/1692.html > which
> re-uses the markup in the W3C example on duplicated elements, and would
> appreciate input. Is this how the UA is supposed to render the markup?
> If so, why?
>
> Sue "trying to clean out old bugs from the Opera bug tracking system" Sims[/color]
An ID can also be used to be pointed at like this:

<a href="#blah">blah</a>

<h1> id="blah">blah</a>

An ID can also be used to be reached with javascript:

document.getElementById('blah').style.backgroundCo lor = "green";

Therefore it also must be unique. If you don't want all that. And just
want 2 elements be styled the same use the class attribute, which is
also allowed on almost all elements.

--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Sue Sims
Guest
 
Posts: n/a
#5: Jul 20 '05

re: ID selectors: duplicated selectors


On Mon, 17 Nov 2003 20:30:42 +0100, Anne van Kesteren
<mail@annevankesteren.nl> wrote:

....<URL: http://css.nu/examples/1692.html >
....[color=blue]
> An ID can also be used to be reached with javascript:[/color]
document.getElementById('blah').style.backgroundCo lor = "green";

Thanks! I modified the TC to include the Javascript. It works as expected
on all the browsers I tested...except that the original ID rule is still
applied to *all* of the duplicates.

I would have thought (hoped) that, like the JavaScript is *only* applied
to the first instance, the markup in the rule:

*#z98y { letter-spacing: 0.3em }

would also be applied to only the first instance.

I'm still hoping that someone can explain why is is applied to _every_
instance.

Alan? Yucca? Steve? Anyone?

Sue
David Leverton
Guest
 
Posts: n/a
#6: Jul 20 '05

re: ID selectors: duplicated selectors


Sue Sims wrote:
[snip][color=blue]
> I find the following text:
> "What makes attributes of type ID special is that no two such attributes
> can have the same value;..."[/color]
[snip][color=blue]
> Given that all of the UAs to which I have access treat all duplicated
> IDs in the above example exactly the same, I was just curious about what
> a UA is *supposed* to do.
>
> Sue[/color]

Since there aren't "supposed" to be multiple elements with the same ID
in the first place, I don't think it's really meaningful to talk about
what UAs are "supposed" to do if there are - except possibly to reject
the document, but that wouldn't be very useful in the real world except
in a validating parser.

Sue Sims
Guest
 
Posts: n/a
#7: Jul 20 '05

re: ID selectors: duplicated selectors


On Mon, 17 Nov 2003 21:49:19 +0000, David Leverton <u01drl3@abdn.ac.uk>
wrote:

[color=blue]
> Since there aren't "supposed" to be multiple elements with the same ID
> in the first place, I don't think it's really meaningful to talk about
> what UAs are "supposed" to do if there are - except possibly to reject
> the document, but that wouldn't be very useful in the real world except
> in a validating parser.[/color]

Or as, in my specific case, trying to decide whether the behavior is a bug
or not. I would expect that an HTML parser would apply the rule to the
first instance of the ID, and show all of the other instances as the
"default". However, that is not the case, *except* in the Javascript that
I applied.

So, I'm no better off that when I asked the original question.

Sue "off to change the TC to xml" Sims
Graham J
Guest
 
Posts: n/a
#8: Jul 20 '05

re: ID selectors: duplicated selectors


> Or as, in my specific case, trying to decide whether the behavior is
a bug[color=blue]
> or not. I would expect that an HTML parser would apply the rule to[/color]
the[color=blue]
> first instance of the ID, and show all of the other instances as the
> "default".[/color]

I would expect that, unless it had some particular interest in error
reporting, an HTML parser might not even bother to check whether there
was an id had already been used and so apply the rule to all
instances. Even if it did discover a reused id I'd consider it quite
reasonable to retain it for rendering purposes. There is no correct
interpretation as the page is invalid.
[color=blue]
> However, that is not the case, *except* in the[/color]
Javascript that[color=blue]
> I applied.[/color]

Apples and oranges. The CSS rule matches all the elements with that
id. The JavaScript requests just one of them then acts on that one
alone(it seems natural that the first one is returned though I could
well imagine the behaviour isn't defined for cases where there is more
than one). You haven't asked it do anything with the other ones.

Ole Kristian Bangås
Guest
 
Posts: n/a
#9: Jul 20 '05

re: ID selectors: duplicated selectors


On Mon, 17 Nov 2003 20:27:17 GMT, Sue Sims <sue@css.nu> wrote:
[color=blue]
> On Mon, 17 Nov 2003 20:30:42 +0100, Anne van Kesteren
> <mail@annevankesteren.nl> wrote:
>
> ...<URL: http://css.nu/examples/1692.html >
> ...[color=green]
>> An ID can also be used to be reached with javascript:[/color]
> document.getElementById('blah').style.backgroundCo lor = "green";
>
> Thanks! I modified the TC to include the Javascript. It works as
> expected on all the browsers I tested...except that the original ID rule
> is still applied to *all* of the duplicates.[/color]

Why do this testing anyway? It seems to me that you're looking for a way
to use the Id for something it was not meant to.
[color=blue]
> I would have thought (hoped) that, like the JavaScript is *only* applied
> to the first instance, the markup in the rule:
>
> *#z98y { letter-spacing: 0.3em }
>
> would also be applied to only the first instance.[/color]

Forget it. If you want it to apply to the first instance, then let the
elements share a classname that you use to apply formatting to all the
elements, and a unique id for each of the elements that you use when
you apply formatting to that single element.
[color=blue]
> I'm still hoping that someone can explain why is is applied to _every_
> instance.[/color]

Let me quote the CSS 2.1 specification which is pretty clear at this point:
<URL: http://www.w3.org/TR/CSS21/selector.html>

E#myid Matches any E element with ID equal to "myid".

--
Ole Kristian Bangås
Stan Brown
Guest
 
Posts: n/a
#10: Jul 20 '05

re: ID selectors: duplicated selectors


In article <opryskt9ndv3x9px@netnews.att.net> in
comp.infosystems.www.authoring.stylesheets, Sue Sims <sue@css.nu>
wrote:[color=blue]
> *#z98y { letter-spacing: 0.3em }
>
>It seems to me that using the universal selector in this example is wrong,
>given the text above which includes "no two such attributes can have the
>same value".[/color]

I'd say redundant rather than wrong. Unless I'm mistaken, that
selector is the same as "#z98y".

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Anne van Kesteren
Guest
 
Posts: n/a
#11: Jul 20 '05

re: ID selectors: duplicated selectors


Stan Brown wrote:[color=blue]
> In article <opryskt9ndv3x9px@netnews.att.net> in
> comp.infosystems.www.authoring.stylesheets, Sue Sims <sue@css.nu>
> wrote:
>[color=green]
>> *#z98y { letter-spacing: 0.3em }
>>
>>It seems to me that using the universal selector in this example is wrong,
>>given the text above which includes "no two such attributes can have the
>>same value".[/color]
>
>
> I'd say redundant rather than wrong. Unless I'm mistaken, that
> selector is the same as "#z98y".
>[/color]
It is the example used by the W3C:
<http://www.w3.org/TR/CSS21/selector.html#id-selectors>. You can also
find it in the CSS3 Selectors draft.

--
Anne van Kesteren
<http://www.annevankesteren.nl/>
David Leverton
Guest
 
Posts: n/a
#12: Jul 20 '05

re: ID selectors: duplicated selectors


Stan Brown wrote:[color=blue]
> In article <opryskt9ndv3x9px@netnews.att.net> in
> comp.infosystems.www.authoring.stylesheets, Sue Sims <sue@css.nu>
> wrote:
>[color=green]
>> *#z98y { letter-spacing: 0.3em }
>>
>>It seems to me that using the universal selector in this example is wrong,
>>given the text above which includes "no two such attributes can have the
>>same value".[/color]
>
>
> I'd say redundant rather than wrong. Unless I'm mistaken, that
> selector is the same as "#z98y".[/color]

Unless you've defined a default namespace with the CSS3 "@namespace"
rule, in which case it only applies to elements in that namespace.

Closed Thread