diff --git a/js/script.js b/js/script.js index e69de29..625f804 100644 --- a/js/script.js +++ b/js/script.js @@ -0,0 +1,75 @@ +$(function(){ + // cache the ul that holds the list + $list = $("ul"); + + //Hide all items and fade them in one at a time + $("li").hide().each( function(i) { + $(this).delay(450 * i).fadeIn(1600); + + }); + + //Update the item counter + function updateItemCount() { + var itemCount = $("li").length; + $("#counter").text(itemCount); + + } + + // Call the funcgtion defined above to update the initial item count + updateItemCount(); + + //Add ability to add a new item to the list + $("#newItemButton").show(); + $("#newItemForm").hide(); + + $("#showForm").on("click", function() { + $("#newItemButton").hide(); + $("#newItemForm").show(); + }); + + // Build the new list item and add it when we click add + $("#add").on("click", function(e) { + // prevent the form submit from refreshing the page + e.preventDefault(); + + //get the text for the item to add, then build/add new li + var text = $("#itemDescription").val(); + var $newItem = $("