Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
simonj-smith committed Aug 5, 2021
1 parent e8e1cb0 commit 8317a8d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Javascript + Dom</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>To do List</h1>
<input id="userinput" type="text" placeholder="Enter Items">
<button id="enter">Add to list!</button>
<ul>

</ul>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
61 changes: 61 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -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<listLength();i++){
deleteButton();
}

function removeParent(evt){
evt.target.parentNode.remove();
}
15 changes: 15 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body{
background-color: yellow;
justify-content: center;
text-align: center;
}



.done {
text-decoration: line-through;
}

li {
list-style: none;
}

0 comments on commit 8317a8d

Please sign in to comment.