-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotes.html
58 lines (53 loc) · 1.57 KB
/
Notes.html
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
<!DOCTYPE html>
<html>
<head>
<title>Notes Application</title>
<style>
form {
margin-bottom: 1rem;
}
.note {
border: 1px solid #ccc;
padding: 1rem;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<h1>Notes Application</h1>
<form id="note-form">
<label for="note-content">New Note:</label>
<textarea id="note-content" rows="4" cols="50"></textarea>
<button type="submit">Save Note</button>
</form>
<div id="notes-container"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const noteForm = document.getElementById('note-form');
const noteContent = document.getElementById('note-content');
const notesContainer = document.getElementById('notes-container');
function displayNotes() {
notesContainer.innerHTML = '';
const notes = JSON.parse(localStorage.getItem('notes')) || [];
notes.forEach(note => {
const noteDiv = document.createElement('div');
noteDiv.className = 'note';
noteDiv.textContent = note;
notesContainer.appendChild(noteDiv);
});
}
noteForm.addEventListener('submit', function(event) {
event.preventDefault();
const content = noteContent.value.trim();
if (!content) return;
const notes = JSON.parse(localStorage.getItem('notes')) || [];
notes.push(content);
localStorage.setItem('notes', JSON.stringify(notes));
noteContent.value = '';
displayNotes();
});
displayNotes();
});
</script>
</body>
</html>