Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Created May 10, 2020 13:42
Show Gist options
  • Save tudorilisoi/f1ac61431f7678eaa5e5c9f57cd77ba5 to your computer and use it in GitHub Desktop.
Save tudorilisoi/f1ac61431f7678eaa5e5c9f57cd77ba5 to your computer and use it in GitHub Desktop.
TODO list
/* 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