-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdom.html
52 lines (43 loc) · 1.19 KB
/
dom.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.spans {
display: flex;
flex-direction: row;
}
.spans>span {
border: 1px solid red;
height: 40px;
width: 40px;
}
.spans>span.dotted {
border: 1px dotted blue;
}
</style>
</head>
<body>
<button>click me</button>
<div id="spans" class="spans">
<span>1</span>
<span class="dotted">2</span>
<span>3</span>
<span>4</span>
<span>5</span>
</div>
<script>
const btn = document.querySelector("button");
btn.addEventListener('click', () => {
const spans = document.querySelector('#spans')
const spansArray = Array.from(spans.querySelectorAll('span'));
spansArray.reverse().forEach(element => {
spans.appendChild(element);
});
})
</script>
</body>
</html>