/
nick.sh
/
javascript-apps
Обзор
Документация
Войти
/
nick.sh
/
javascript-apps
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
notes_app/script.js
42 строки
1 KB
Shaposhnikov-Nick
notes_app
30 янв 2024, 16:50
30 янв 2024, 16:50
a5263e3
Код
Авторство
О чём код?
const notesContainer = document.querySelector(".notes-container"); const createBtn = document.querySelector(".btn"); let notes = document.querySelector(".input-box"); function showNotes() { notesContainer.innerHTML = localStorage.getItem("notes"); } showNotes(); function updateStorage() { localStorage.setItem("notes", notesContainer.innerHTML); } createBtn.addEventListener("click", () => { let inputBox = document.createElement("p"); let img = document.createElement("img"); inputBox.className = "input-box"; inputBox.setAttribute("contenteditable", "true"); img.src = "images/delete.png"; notesContainer.appendChild(inputBox).appendChild(img); }); notesContainer.addEventListener("click", (event) => { if (event.target.tagName === "IMG") { event.target.parentElement.remove(); updateStorage(); } else if (event.target.tagName === "P") { notes = document.querySelectorAll(".input-box"); notes.forEach((note) => { note.onkeyup = function () { updateStorage(); }; }); } }); document.addEventListener("keydown", (event) => { if (event.key === "Enter") { document.execCommand("insertLineBreak"); event.preventDefault(); } });