Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /dom/nodes/getElementsByClassName-whitespace-class-names.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Node.prototype.getElementsByClassName with no real class names</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<span class="">LINE TABULATION</span>
<span class="…">NEXT LINE</span>
<span class=" ">NO-BREAK SPACE</span>
<span class=" ">OGHAM SPACE MARK</span>
<span class=" ">EN QUAD</span>
<span class=" ">EM QUAD</span>
<span class=" ">EN SPACE</span>
<span class=" ">EM SPACE</span>
<span class=" ">THREE-PER-EM SPACE</span>
<span class=" ">FOUR-PER-EM SPACE</span>
<span class=" ">SIX-PER-EM SPACE</span>
<span class=" ">FIGURE SPACE</span>
<span class=" ">PUNCTUATION SPACE</span>
<span class=" ">THIN SPACE</span>
<span class=" ">HAIR SPACE</span>
<span class="
">LINE SEPARATOR</span>
<span class="
">PARAGRAPH SEPARATOR</span>
<span class=" ">NARROW NO-BREAK SPACE</span>
<span class=" ">MEDIUM MATHEMATICAL SPACE</span>
<span class=" ">IDEOGRAPHIC SPACE</span>
<span class="᠎">MONGOLIAN VOWEL SEPARATOR</span>
<span class="​">ZERO WIDTH SPACE</span>
<span class="‌">ZERO WIDTH NON-JOINER</span>
<span class="‍">ZERO WIDTH JOINER</span>
<span class="⁠">WORD JOINER</span>
<span class="">ZERO WIDTH NON-BREAKING SPACE</span>
<script>
"use strict";
const spans = document.querySelectorAll("span");
for (const span of spans) {
test(() => {
const className = span.getAttribute("class");
assert_equals(className.length, 1, "Sanity check: the class name was retrieved and is a single character");
const shouldBeSpan = document.getElementsByClassName(className);
assert_array_equals(shouldBeSpan, [span]);
}, `Passing a ${span.textContent} to getElementsByClassName still finds the span`);
}
</script>