Skip to content

Instantly share code, notes, and snippets.

@davidcroda
Created June 11, 2015 14:19
Show Gist options
  • Save davidcroda/1a9cfe868c8ee294f20c to your computer and use it in GitHub Desktop.
Save davidcroda/1a9cfe868c8ee294f20c to your computer and use it in GitHub Desktop.
$(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