Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created January 15, 2020 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/71bdec5eb162888c7ad89100c393b21e to your computer and use it in GitHub Desktop.
Save stoneboyindc/71bdec5eb162888c7ad89100c393b21e to your computer and use it in GitHub Desktop.
'use strict';
$(function () {
$('#js-shopping-list-form').submit(
function (event) {
event.preventDefault();
const targetItem = $('#shopping-list-entry').val();
const listItemTemplate = (`<li>
<span class="shopping-item">
${targetItem}
</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(listItemTemplate);
}
//,$('#js-shopping-list-form').empty());
)
});
$('.shopping-item-toggle').on('click', function () {
event.preventDefault();
$('.shoppingItem').toggle(function () {
(this).css({ 'text-decoration': 'line-through' });
});
}
//when we click the "delete" we want to remove the entire related <li>
, $('.shopping-item-delete').on('click', function () {
event.preventDefault();
$(this).closest("li").remove();
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment