-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (55 loc) · 1.65 KB
/
Copy pathindex.js
File metadata and controls
69 lines (55 loc) · 1.65 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// add new Item to the list
// chech and uncheck existing items
// permenantly delete item
$(function (){
addNewItem();
clearTheForm();
getTheItemName();
deleteItem();
checkAndUcheckItem();
})
function addNewItem(){
$("#js-shopping-list-form").on("submit", event => {
event.preventDefault();
buildANewItem(getTheItemName());
checkAndUcheckItem();
clearTheForm();
})
}
function clearTheForm(){
$("#js-shopping-list-form").trigger('reset');
}
function getTheItemName(){
let itemName = $('.js-shopping-list-entry').val();
return itemName;
}
function buildANewItem(item){
//console.log(item);
let newItem = `<li>
<span class="shopping-item">${item}</span>
<div class="shopping-item-controls">
<button class="shopping-item-toggle">
<span class="button-label">check</span>
</button>
<button class="shopping-item-delete">
<span class="button-label">delete</span>
</button>
</div>
</li>`
$('.shopping-list').append(newItem);
deleteItem();
return newItem;
}
function deleteItem(){
$('.shopping-item-delete').on('click', event => {
//$(this).parent('li').remove();
//$(this).closest('li').remove();
$('.shopping-item-delete').parents('li').first().remove();
})
}
function checkAndUcheckItem(){
$('.shopping-item-toggle').on('click', event => {
// console.log($('.shopping-item-toggle').parents('span').first().toggleClass('shopping-item__checked'));
$(event.target).closest("li").find('span').toggleClass('shopping-item__checked');
})
}