Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created January 27, 2020 15:47
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/cbe5d5ac1d783a8ae89afc2810f833e5 to your computer and use it in GitHub Desktop.
Save stoneboyindc/cbe5d5ac1d783a8ae89afc2810f833e5 to your computer and use it in GitHub Desktop.
$(function() {
$('#js-shopping-list-form').submit(function(event) {
event.preventDefault();
const item = $('#shopping-list-entry').val();
$('.shopping-list').prepend(
`<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>`);
registerEvents();
});
});
function registerEvents() {
$('.shopping-item-delete').on("click", function(event) {
$(this).closest('li').remove();
});
$('.shopping-item-toggle').on("click", function(event) {
$(this).closest('li').find('.shopping-item').toggleClass('shopping-item shopping-item__checked');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment