Last active
January 15, 2020 15:28
-
-
Save stoneboyindc/fc97e69950123f616035e687aba0889e 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
function onReady(){ | |
const addToDoForm = document.getElementById('addToDoForm'); | |
const newToDoText = document.getElementById ('newToDoText'); | |
const toDoList = document.getElementById ('toDoList'); | |
addToDoForm.addEventListener('submit', event => { | |
event.preventDefault(); | |
// get the text | |
let title = newToDoText.value; | |
// create a new li | |
let newLi = document.createElement('li'); | |
//create a new input | |
let checkbox = document.createElement('input'); | |
//set the input's type to checkbox | |
checkbox.type = "checkbox"; | |
//set the title: | |
newLi.textContent = title; | |
// attach the checkbox to the li | |
newLi.appendChild(checkbox); | |
// attach the li to the ul | |
toDoList.appendChild(newLi); | |
//empty the input | |
newToDoText.value = ''; | |
let deleteBtn = document.createElement('button'); | |
deleteBtn.textContent = "Delete"; | |
newLi.appendChild(deleteBtn); | |
deleteBtn.addEventListener('click', function(event){ | |
toDoList.removeChild(this.parentElement); | |
}); | |
}) | |
} | |
window.onload = function(){ | |
alert("The window has loaded!"); | |
onReady(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment