FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript_Projects/Notes_App/script.js at main · AkshitKumarBansal/JavaScript_Projects · GitHub
AkshitKumarBansal
/
JavaScript_Projects
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript_Projects
/
Notes_App
/
script.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (34 loc) · 1.23 KB
Breadcrumbs
JavaScript_Projects
/
Notes_App
/
script.js
Copy path
File metadata and controls
39 lines (34 loc) · 1.23 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
const
input
=
document
.
getElementById
(
'input'
)
;
const
submitBtn
=
document
.
getElementById
(
'submit'
)
;
const
notesContainer
=
document
.
getElementById
(
'notes-container'
)
;
let
notesArray
=
JSON
.
parse
(
localStorage
.
getItem
(
'myNotes'
)
)
||
[
]
;
function
renderNotes
(
)
{
notesContainer
.
innerHTML
=
''
;
notesArray
.
forEach
(
(
noteText
,
index
)
=>
{
createNoteElement
(
noteText
,
index
)
;
}
)
}
submitBtn
.
addEventListener
(
'click'
,
(
)
=>
{
const
noteText
=
input
.
value
.
trim
(
)
;
if
(
noteText
!==
''
)
{
createNoteElement
(
noteText
)
;
notesArray
.
push
(
noteText
)
;
localStorage
.
setItem
(
'myNotes'
,
JSON
.
stringify
(
notesArray
)
)
;
renderNotes
(
)
;
input
.
value
=
''
;
}
}
)
function
createNoteElement
(
noteText
,
index
)
{
const
noteElement
=
document
.
createElement
(
'div'
)
;
noteElement
.
classList
.
add
(
'note'
)
;
noteElement
.
innerHTML
=
`<div class="note-text">
${
noteText
}
</div><button class="delete-btn">Delete</button>`
;
notesContainer
.
appendChild
(
noteElement
)
;
const
deleteBtn
=
noteElement
.
querySelector
(
'.delete-btn'
)
;
deleteBtn
.
addEventListener
(
'click'
,
(
)
=>
{
notesArray
.
splice
(
index
,
1
)
;
notesContainer
.
removeChild
(
noteElement
)
;
localStorage
.
setItem
(
'myNotes'
,
JSON
.
stringify
(
notesArray
)
)
;
renderNotes
(
)
;
}
)
}
renderNotes
(
)
;
Back
|
FazBrowse Home
|
New Git URL