-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path15-DOM API - JavaScript Tutorial for beginners.js
More file actions
94 lines (58 loc) · 1.91 KB
/
15-DOM API - JavaScript Tutorial for beginners.js
File metadata and controls
94 lines (58 loc) · 1.91 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// document.onclick = () => {
// console.log('KHELLO DOM')
// }
// document.body.append('MY NEW THINGY')
// document.body.appendChild('YET ANOTHER THINGY')
// const myHeading = document.createElement('h1')
// document.appendChild(myHeading)
// document.body.appendChild(myHeading)
// myHeading.innerText = 'I AM YOUR HEADER'
// myHeading.innerText = 'Cucumber 🥒'
// const now = new Date()
// myHeading.innerText = `${now.getHours}:${now.getMinutes}`
//-----------------------------
// const input = document.createElement('input')
// input.placeholder = 'TO DO'
// document.body.appendChild(input)
// button.value = 'ADD'
// document.body.appendChild(button)
// button.innerText = 'ADD'
// button.addEventListener('click', () => {
// const div = document.createElement('div')
// div.innerText = input.value
// document.body.appendChild(div)
// })
//-----------------------------
document.body.innerText = ''
const form = document.createElement('form')
document.body.appendChild(form)
const input = document.createElement('input')
input.placeholder = 'TO DO'
form.appendChild(input)
const button = document.createElement('button')
button.innerText = 'ADD'
button.role = 'submit'
form.appendChild(button)
const ul = document.createElement('ul')
document.body.appendChild(el)
const removeElement = el => {
console.log(el)
}
form.onsubmit = (e) => {
e.preventDefault()
const li = document.createElement('li')
ul.appendChild(li)
li.innerText = input.value
li.onclick = removeElement.bind(null, li)
input.value = ''
}
document.body.style.padding = '16px'
input.style.marginRight = '8px'
document.body.style.backgroundColor = 'white'
document.body.attributes
document.body.setAttribute('class', blue)
document.getElementsByClassName('blue')
document.getElementsByTagName('li')
document.querySelector('.blue')
document.querySelectorAll('.blue')
document.querySelectorAll('li')