-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (46 loc) · 1.67 KB
/
Copy pathscript.js
File metadata and controls
54 lines (46 loc) · 1.67 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
let notes = [];
function addNote() {
const title = document.getElementById('title').value.trim();
const content = document.getElementById('content').value.trim();
if (!title || !content) return alert('Please fill in both fields.');
notes.push({ title, content });
document.getElementById('title').value = '';
document.getElementById('content').value = '';
renderNotes();
}
function renderNotes(filter = '') {
const container = document.getElementById('notes');
container.innerHTML = '';
notes
.filter(note =>
note.title.toLowerCase().includes(filter.toLowerCase()) ||
note.content.toLowerCase().includes(filter.toLowerCase())
)
.forEach((note, index) => {
const noteEl = document.createElement('div');
noteEl.className = 'note';
noteEl.innerHTML = `
<h3 contenteditable="true" onblur="updateTitle(${index}, this.innerText)">${note.title}</h3>
<p contenteditable="true" onblur="updateContent(${index}, this.innerText)">${note.content}</p>
<button onclick="editNote(${index})">Edit</button>
<button class="delete" onclick="deleteNote(${index})">Delete</button>
`;
container.appendChild(noteEl);
});
}
function deleteNote(index) {
notes.splice(index, 1);
renderNotes();
}
function editNote(index) {
alert('You can edit the title/content directly. Changes are auto-saved.');
}
function updateTitle(index, newTitle) {
notes[index].title = newTitle;
}
function updateContent(index, newContent) {
notes[index].content = newContent;
}
document.getElementById('search').addEventListener('input', function () {
renderNotes(this.value);
});