Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Last active January 15, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoneboyindc/fc97e69950123f616035e687aba0889e to your computer and use it in GitHub Desktop.
Save stoneboyindc/fc97e69950123f616035e687aba0889e to your computer and use it in GitHub Desktop.
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