summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/nodes/getElementsByClassName-32.html
blob: 29eb41353ce88ddb27716279ae7574d8dfcb1ad8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>Node.prototype.getElementsByClassName tests imported from jsdom</title>
<link rel=help href="https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div class="df-article" id="1">
</div>
<div class="df-article" id="2">
</div>
<div class="df-article" id="3">
</div>

<script>
"use strict";

test(() => {

  const p = document.createElement("p");
  p.className = "unknown";
  document.body.appendChild(p);

  const elements = document.getElementsByClassName("first-p");
  assert_array_equals(elements, []);

}, "cannot find the class name");

test(() => {

  const p = document.createElement("p");
  p.className = "first-p";
  document.body.appendChild(p);

  const elements = document.getElementsByClassName("first-p");
  assert_array_equals(elements, [p]);

}, "finds the class name");


test(() => {

  const p = document.createElement("p");
  p.className = "the-p second third";
  document.body.appendChild(p);

  const elements1 = document.getElementsByClassName("the-p");
  assert_array_equals(elements1, [p]);

  const elements2 = document.getElementsByClassName("second");
  assert_array_equals(elements2, [p]);

  const elements3 = document.getElementsByClassName("third");
  assert_array_equals(elements3, [p]);

}, "finds the same element with multiple class names");

test(() => {

  const elements = document.getElementsByClassName("df-article");

  assert_equals(elements.length, 3);
  assert_array_equals(Array.prototype.map.call(elements, el => el.id), ["1", "2", "3"]);

}, "does not get confused by numeric IDs");

</script>