Created
May 10, 2020 13:42
-
-
Save tudorilisoi/f1ac61431f7678eaa5e5c9f57cd77ba5 to your computer and use it in GitHub Desktop.
TODO list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* const listItemTemp = ('<li>' + | |
'<span class="shopping-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>' | |
); */ | |
//Append to end | |
$(function () { | |
$('button[type="submit"]').click(function () { | |
const mylist = $('#shopping-list-entry').val(); | |
$('.shopping-list').append(` | |
<li> | |
<span class="shopping-item">${mylist}</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> | |
`) | |
return false; | |
}) | |
}) | |
//"Check" button clicked | |
$(function completed() { | |
console.log('Selecting...') | |
$(".shopping-list").on("click", ".shopping-item-toggle", function (event) { | |
console.log('Event is:', event) | |
const $name = $(event.currentTarget).parents('li').find('.shopping-item') | |
$name.toggleClass('shopping-item__checked') | |
}); | |
}) | |
//"Delete" button removing items | |
$(function () { | |
$(".shopping-list").on("click", ".shopping-item-delete", function (event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
const $li = $(event.currentTarget).parents('li') | |
$li.remove() | |
// $('.shopping-item').remove(); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment