FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-DOM-Tutorial/app.js at lesson-15 · racalhoun/JavaScript-DOM-Tutorial · GitHub
racalhoun
JavaScript-DOM-Tutorial
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-DOM-Tutorial
/
app.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (38 loc) · 1.1 KB
Breadcrumbs
JavaScript-DOM-Tutorial
/
app.js
Copy path
File metadata and controls
45 lines (38 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
list
=
document
.
querySelector
(
'#book-list ul'
)
;
const
forms
=
document
.
forms
;
// delete books
list
.
addEventListener
(
'click'
,
(
e
)
=>
{
if
(
e
.
target
.
className
==
'delete'
)
{
const
li
=
e
.
target
.
parentElement
;
li
.
parentNode
.
removeChild
(
li
)
;
}
}
)
;
// add books
const
addForm
=
forms
[
'add-book'
]
;
addForm
.
addEventListener
(
'submit'
,
function
(
e
)
{
e
.
preventDefault
(
)
;
// create elements
const
value
=
addForm
.
querySelector
(
'input[type="text"]'
)
.
value
;
const
li
=
document
.
createElement
(
'li'
)
;
const
bookName
=
document
.
createElement
(
'span'
)
;
const
deleteBtn
=
document
.
createElement
(
'span'
)
;
// add text content
bookName
.
textContent
=
value
;
deleteBtn
.
textContent
=
'delete'
;
// add classes
bookName
.
classList
.
add
(
'name'
)
;
deleteBtn
.
classList
.
add
(
'delete'
)
;
// append to DOM
li
.
appendChild
(
bookName
)
;
li
.
appendChild
(
deleteBtn
)
;
list
.
appendChild
(
li
)
;
}
)
;
// hide books
const
hideBox
=
document
.
querySelector
(
'#hide'
)
;
hideBox
.
addEventListener
(
'change'
,
function
(
e
)
{
if
(
hideBox
.
checked
)
{
list
.
style
.
display
=
"none"
;
}
else
{
list
.
style
.
display
=
"initial"
;
}
}
)
;
Back
|
FazBrowse Home
|
New Git URL