Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/* Новые элементы должны добавляться в список по нажатию на Enter */
const container = document.querySelector(".container");
const input = document.querySelector("#input");
const items = document.querySelector("#items");

/* Пустые элементы не должны добавляться */
function addItem() {
const itemText = input.value.trim();
if (itemText !== '') {
const listitem = document.createElement('li');
listitem.textContent = itemText;
listitem.addEventListener('click', function() {
listitem.classList.toggle('done');
});
items.appendChild(listitem);
input.value = '';
}
}

/* Если кликнуть на элемент списка, он зачеркивается */
input.addEventListener('keydown', function(event) {
if (event.key == 'Enter') {
addItem();
}

/* Если кликнуть повторно уже на зачеркнутый, он снова становится обычным */

/* Очищать input после добавления нового элемента в список */
});