Created
June 11, 2015 14:19
-
-
Save davidcroda/1a9cfe868c8ee294f20c 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
$(document).ready(function(){ | |
// Get text from form input and display on list | |
$(".add").on("click", function(){ | |
event.preventDefault(); // lets the user hit "enter" instead of having to click the "+" block | |
var item = $("input[name=item]").val(); | |
// If no letters are entered, an alert message will pop up | |
if (item <= 0) { | |
alert ("Please add an item") | |
} else { | |
$("#shopping-list").append("<li>" + "<a class=remove>x</a>" + " " + item + "</li>"); | |
$("input[name=item]").val(""); | |
} | |
}) | |
// The following changes the item to completed | |
$("li").on('click', function() {$(this).toggleClass("completed");}); | |
// The following removes the item from the list after it has been added | |
$(".remove").on('click', function() {$(this).closest("li").remove();}); | |
// Resets the shopping list | |
$(".reset").click(function() {$("#shopping-list").empty();}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment