Created
January 9, 2015 18:27
-
-
Save ryansobol/e1957de59a581b0c460f 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.getElementById("todo").addEventListener("keypress", function(event) { | |
if (event.keyCode == 13) { | |
addToDo(); | |
} | |
}); | |
function addToDo() { | |
var newEl = document.createElement("li"); | |
var parentEl = document.getElementById("list"); | |
var firstEl = parentEl.firstChild; | |
newEl.innerHTML = document.myform.todo.value; | |
newEl.addEventListener("click", function() { | |
removeToDo(parentEl, newEl); | |
}); | |
parentEl.insertBefore(newEl, firstEl); | |
}; | |
function removeToDo(parentEl, newEl) { | |
parentEl.removeChild(newEl); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment