W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2005

[whatwg] getElementsByClassName() Implementation Questions

From: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Date: Sun, 04 Sep 2005 13:20:05 +1000
Message-ID: <431A67E5.8030202@lachy.id.au>
Hi,
   I have a partial implementation of getElementsByClassName() [1] that 
is designed to support HTML, XHTML, MathML and SVG documents (including 
mixed namespace documents).  It also includes Element.hasClassName(), 
Element.addClassName() and Element.removeClassName(), which I think 
should also be added to WA1.

It's currently known to workw in Firefox, Opera and IE using an HTC.  It 
should work in any standards compliant browser that supports DOM2, 
though I don't know about non-Windows browsers.  However, I have some 
questions about the expected result from some of the following test cases.

Given these HTML elements:

A: <p class="foo">
B: <p class=" foo">
C: <p class="foo ">
D: <p class=" foo ">
E: <p class="foo bar">
F: <p class="foo 	bar">
G: <p class="bar foo">
H: <p class="foobar">
I: <p class="foo-bar">
J: <p class="FOO">

What should each of these function calls return?  I've listed the ones 
that my script currently selects.  Are any of them incorrect?

01. getElementsByClassName("");           | (none)
02. getElementsByClassName(" ");          | (none)
03. getElementsByClassName("foo");        | A, B, C, D, E, F, G
04. getElementsByClassName(" foo");       | A, B, C, D, E, F, G
05. getElementsByClassName("foo ");       | A, B, C, D, E, F, G
06. getElementsByClassName(" foo ");      | A, B, C, D, E, F, G
07. getElementsByClassName("foo bar");    | E, F
08. getElementsByClassName("foo", "bar"); | E, F, G
09. getElementsByClassName("bar", "foo"); | E, F, G
10. getElementsByClassName("foo", "foo"); | A, B, C, D, E, F, G

Lastly, if anyone find any other test cases where my script fails in any 
browser, please let me know.  If you can suggest a fix, that would be 
even better.

[1] http://lachy.id.au/dev/script/examples/DOM/

-- 
Lachlan Hunt
http://lachy.id.au/
Received on Saturday, 3 September 2005 20:20:05 UTC

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