[whatwg] getElementsByClassName()

Lachlan Hunt lachlan.hunt at lachy.id.au
Fri Feb 3 06:06:17 PST 2006


Ric Hardacre wrote:
> Gervase Markham wrote:
>> If you have:
>>
>> <p class="foo bar">Fred</p>
>> <p class="bar foo">Barney</p>
>> <p class="foo baz bar">Wilma</p>
>>
>> which should be picked up by getElementsByClassName("foo bar")?
> 
> this also raises the possibility of some confusion as the order of 
> inheritance is important:
> 
> foo
> {
>    color: red;
> }
> 
> bar
> {
>    color: blue;
> }
> 
> in the quoted example Fred and Wilma would be blue and barney red.

According to which rules specified in CSS will that be the case?  Given 
that CSS (assuming you meant to use class selectors instead), all three 
markup samples will be blue.  The order of the class names in the markup 
is irrelevant.  The order of the rules specified in the CSS is relevant 
and the latter rule of equal specificity takes precedence.

-- 
Lachlan Hunt
http://lachy.id.au/




More information about the whatwg mailing list