From 9a7edbfa3a79fe34b7e4a4c3ac3b72bd26a5cb14 Mon Sep 17 00:00:00 2001 From: Benjamin White Date: Mon, 11 Jul 2016 16:30:45 -0400 Subject: [PATCH 1/3] it works! --- app.js | 43 +++++++++++++++++++++++++++++++++++++++++++ index.html | 9 +++++---- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 00000000..49f4e496 --- /dev/null +++ b/app.js @@ -0,0 +1,43 @@ +$(document).ready(function() { + + // logic for adding an item to shopping list + $("#js-shopping-list-form").submit(function(event) { + // stops default browser behavior for form submission, + // since we don't actually want to submit to server + event.preventDefault(); + + // add new item to botom of list + $('.shopping-list').append( + '
  • ' + + '' + $("#shopping-list-entry").val() + '' + + '
    ' + + '' + + '' + + '
    ' + + '
  • ' + ); + // remove the submitted item from the form input + $(this)[0].reset(); + }); + + // logic for deleting items from list + $(".shopping-list").on("click", ".shopping-item-delete", function(event){ + // here `this` refers to the `.shopping-item-delete` element that was clicked. + // we travel up the document tree to get the nearest parent element + // that"s an `li` + $(this).closest("li").remove(); + }); + + // logic for checking/unchecking items + $(".shopping-list").on("click", ".shopping-item-toggle", function(event){ + + // toggle the .shopping-item__checked class + $(this).closest("li").find(".shopping-item").toggleClass( + "shopping-item__checked"); + }); + +}) \ No newline at end of file diff --git a/index.html b/index.html index 17eed56c..cbbb5e7d 100644 --- a/index.html +++ b/index.html @@ -13,9 +13,9 @@

    Shopping List

    -
    - - + + +
    @@ -66,6 +66,7 @@

    Shopping List

    - + + \ No newline at end of file From 51b44ac1d1f05825928ca919bc5ea8f77dd04b3f Mon Sep 17 00:00:00 2001 From: Benjamin White Date: Mon, 11 Jul 2016 18:40:37 -0400 Subject: [PATCH 2/3] update text --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index cbbb5e7d..a6f0e276 100644 --- a/index.html +++ b/index.html @@ -46,7 +46,7 @@

    Shopping List

    milk