-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (64 loc) · 2.54 KB
/
main.js
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
let text = document.querySelector('input');
let button = document.querySelector('button');
let element = document.querySelector('.special');
button.addEventListener('click', function() {
let wrapper = document.createElement('div');
wrapper.classList.add('wrapper');
let h1 = document.createElement('h1');
h1.innerHTML = text.value;
let Minus = document.createElement('button');
Minus.innerHTML = '-';
let ArrowUp = document.createElement('button');
ArrowUp.innerHTML = "↑"
let ArrowDown = document.createElement('button');
ArrowDown.innerHTML = "↓"
let SymbolNumber = document.createElement('span');
element.appendChild(wrapper);
let wrapperAll = document.querySelectorAll('.wrapper');
for (let j = 0; j < wrapperAll.length; j++) {
SymbolNumber.innerHTML = j + 1;
}
wrapper.appendChild(SymbolNumber);
wrapper.appendChild(h1);
wrapper.appendChild(Minus);
wrapper.appendChild(ArrowUp);
wrapper.appendChild(ArrowDown);
Minus.addEventListener('click', function() {
Minus.parentNode.remove();
let wrapperAll = document.querySelectorAll('.wrapper');
let SymbolNum = document.querySelectorAll('span');
for (let i = 0; i < wrapperAll.length; i++) {
SymbolNum[i].innerHTML = i + 1;
};
})
ArrowUp.addEventListener('click', function() {
let wrapperAll = document.querySelectorAll('.wrapper');
for (let i = 0; i < wrapperAll.length; i++) {
if (ArrowUp.parentNode == wrapperAll[i]) {
let parent = wrapperAll[i].parentNode;
parent.insertBefore(wrapperAll[i], wrapperAll[i - 1])
}
}
let SymbolNum = document.querySelectorAll('span');
for (let i = 0; i < wrapperAll.length; i++) {
SymbolNum[i].innerHTML = i + 1;
};
})
ArrowDown.addEventListener('click', function() {
let wrapperAll = document.querySelectorAll('.wrapper');
for (let i = 0; i < wrapperAll.length; i++) {
if (ArrowDown.parentNode == wrapperAll[i]) {
let parent = wrapperAll[i].parentNode;
if (i === wrapperAll.length - 1) {
parent.insertBefore(wrapperAll[i], wrapperAll[0]);
} else {
parent.insertBefore(wrapperAll[i + 1], wrapperAll[i])
}
}
}
let SymbolNum = document.querySelectorAll('span');
for (let i = 0; i < wrapperAll.length; i++) {
SymbolNum[i].innerHTML = i + 1;
};
})
});