-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (47 loc) · 1.82 KB
/
index.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
function setplayer_name(){
let x= localStorage.getItem('userName') ?? 'Mystery player';
const playerNameEl = document.querySelector('.player-name');
playerNameEl.textContent = x;
}
setplayer_name();
const addbutton = document.getElementsByClassName("form_button");
addbutton[0].addEventListener("click",button_click,false);
let b = 1;
function button_click(e){
e.preventDefault();
const input_element = document.getElementsByClassName("input1")[0];
const table= document.getElementsByClassName("table1")[0];
const date = document.createElement("td");
const url = document.createElement("td");
url.style.textAlign = "center";
const button_row = document.createElement("td");
const newrow = document.createElement("tr");
const button = document.createElement("button");
button.textContent = "delete";
button.style.fontSize ="medium";
button.className='delete'+b;
button.type = "submit";
date.textContent = "11/01/2023";
url.textContent = input_element.value;
button_row.appendChild(button);
button_row.dataset.id = b;
newrow.appendChild(date);
newrow.appendChild(url);
newrow.appendChild(button_row);
table.appendChild(newrow);
newrow.className ='add'+b;
for(let i =0; i<b;i++){
const deleteButton = document.getElementsByClassName("delete"+b);
deleteButton[0].addEventListener("click",delete_click,false);}
input_element.value = '';
b++;
}
// let i =1;
// const deleteButton = document.getElementsByClassName("delete"+b);
// deleteButton[0].addEventListener("click",delete_click,false);
function delete_click(e){
e.preventDefault();
const id = e.target.parentNode.dataset.id;
const rowElement = document.querySelector('.add' + id);
rowElement.parentNode.removeChild(rowElement);
}