Created
January 27, 2020 15:47
-
-
Save stoneboyindc/cbe5d5ac1d783a8ae89afc2810f833e5 to your computer and use it in GitHub Desktop.
This file contains 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
$(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