[whatwg] getElementsByClassName() Implementation Questions

Lachlan Hunt lachlan.hunt at lachy.id.au
Sat Sep 3 20:20:05 PDT 2005


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/




More information about the whatwg mailing list