From 8317a8dac8ceab32456542c79966d7683c6b6c24 Mon Sep 17 00:00:00 2001 From: "simonj.smith" Date: Thu, 5 Aug 2021 12:26:32 +0100 Subject: [PATCH] Add files --- index.html | 17 +++++++++++++++ script.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 15 ++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 0000000..0e6907f --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + Javascript + Dom + + + +

To do List

+ + + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..f1af562 --- /dev/null +++ b/script.js @@ -0,0 +1,61 @@ +var input = document.getElementById("userinput"); +var button = document.getElementById("enter"); +var ul = document.querySelector("ul"); +var listItems=document.getElementsByTagName("li"); + + +function inputLength(){ + return input.value.length; +} + + +function createListElement(){ + var li=document.createElement("li"); + li.appendChild(document.createTextNode(input.value)); + ul.appendChild(li); + input.value=""; + + var btn = document.createElement("button"); + btn.appendChild(document.createTextNode("Delete")); + li.appendChild(btn); + btn.onclick = removeParent; +} + +function addListAfterClick(){ + if(inputLength() > 0){ + createListElement(); + } +} + +function addListAfterKeypress(event){ + if(inputLength() > 0 && event.keyCode === 13){ + createListElement(); + } +} + +button.addEventListener("click",addListAfterClick); + +input.addEventListener("keypress",addListAfterKeypress); + +ul.onclick=function(event){ + var target=event.target; + target.classList.toggle("done"); +} + +function listLength(){ + return listItems.length; +} + +function deleteButton(){ + var btn=document.createElement("button"); +btn.appendChild(document.createTextNode("Delete!")); +listItems[i].appendChild(btn); +btn.onclick=removeParent;} + +for(i=0;i