diff --git a/index.html b/index.html index fa08eb38..6468585c 100644 --- a/index.html +++ b/index.html @@ -66,6 +66,10 @@

Shopping List

- + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 00000000..874dbf49 --- /dev/null +++ b/index.js @@ -0,0 +1,42 @@ +/* eslint-disable no-undef */ +'use strict'; + +function addItem() { + $('#js-shopping-list-form').submit( event => { + event.preventDefault(); + const newItem = $(event.currentTarget).find('input[name="shopping-list-entry"]').val(); + const newItemHTML = + `
  • + ${newItem} +
    + + +
    +
  • `; + $('.shopping-list').append(newItemHTML); + }); +} + +function checkItem() { + $('.shopping-list').on('click', '.shopping-item-toggle', function() { + $(this).closest('li').find('.shopping-item').toggleClass('shopping-item__checked'); + }); +} + +function removeItem() { + $('.shopping-list').on('click', '.shopping-item-delete', function() { + $(this).closest('li').remove(); + }); +} + +function main() { + addItem(); + checkItem(); + removeItem(); +} + +$(main); \ No newline at end of file