Created
February 5, 2015 15:14
-
-
Save al-the-x/3396906d9cad95ff1755 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() { | |
$('#new-todo').on('keypress', function(event) { | |
// If the "Enter" key is pressed... | |
if (event.which == 13) { | |
//append to the <ul> | |
var inputVal = $('#new-todo').val(); | |
// Grab the value of the `#new-todo` <input> element... | |
var newTask = // Use this template... | |
$("<li>" + | |
"<div class='view'>" + | |
"<input class='toggle' type='checkbox'>" + | |
"<label>" + inputVal + "</label>" + | |
"<button class='destroy'></button>" + | |
"</div>" + | |
"<input class='edit' value=''>" + | |
"</li>"); | |
$('#todo-list').append(newTask); | |
// Append the template to the `#todo-list` element... | |
$('#new-todo').val(''); | |
// Reset the value of the `#new-todo` <input> element... | |
}; // END if(enter key) | |
}); // END on(keypress) | |
//toggle label.completed if checkbox == true | |
$('#todo-list').on('click', '.toggle', function(event) { | |
// Walk back up the tree to the nearest <li>... | |
$(this).closest('li') | |
.toggleClass('completed'); | |
// Mark it as ".completed" (or not maybe) | |
// alert('clicked'); | |
}); //toggling the label complete class | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment