W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2006

[whatwg] getElementsByClassName()

From: Ric Hardacre <whatwg@cycloid.f9.co.uk>
Date: Fri, 03 Feb 2006 13:31:37 +0000
Message-ID: <43E35B39.9060601@cycloid.f9.co.uk>


Gervase Markham wrote:
 > Brad Fults wrote:
 >> I see this is still an open issue[1]. Is this now implemented as #1
 >> (space-delimited class names to match)?
 >>
 >> I suggest either going with the space-delimited approach (as it's
 >> language-agnostic and well-defined at least) or with Aankhen's
 >> suggestion of a single array argument.
 >
 > Musing...
 >
 > 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. so 
the distinction between class="foo bar" and class="bar foo" is real, not 
merely syntactic. a search for "foo" should pick up either but a search 
for "foo bar" should only find the first, so IMO a comma seperated list 
would be better in that respect:

1. getElementsByClassName("foo bar,foo tang,woo tang")

this use of explicit class matching could, however be considered an 
"advanced" use of the function, with emphasis on the simpler:

2. getElementsByClassName("bar,tang")

as an aside this then yields another level of even more complex 
behavioural possibilities:

3. getElementsByClassName("foo>bar")

though in this example the ClassName, having not being explicitly 
declared in the markup. is not what is being selected, but a derived 
inheritance, perhaps warranting a new function

4. getElementsByRelationship("foo:firstChild")

what this would mean, therefore is that

5. <div class="foo bar">

would be selected by example 1. whereas

6. <div class="foo"><div class="bar">

would be selected by example 3. specifically and example 4. if the 
designer wanted to make assumptions about the resuting DOM

Ric
Received on Friday, 3 February 2006 05:31:37 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:26 UTC