Skip to content

Commit

Permalink
created basic todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
allyford committed Apr 7, 2019
0 parents commit b08203f
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>

<body>
<input id="todo-item-text">
<button id="button-add" onclick="addItem()">Add todo</button>
<ul id="todo-list">
<li class="todo-item">
<button class="button-delete" onclick="deleteItem(this)">X</button>
item 1
</li>
</ul>

</body>

</html>

<style>

li {
list-style-type: none;
font-size: 18px;
}

.button-delete {
margin-right: 10px;
}

</style>

<script>
function addItem() {
// get the todo-item-text value
let newItemText = document.getElementById('todo-item-text').value;

// check if the newItemText is empty
if (newItemText === '') {
alert('You cannot add an empty todo item you silly goose!');
return;
}

let todoList = document.getElementById('todo-list');

let newListItem = document.createElement('li');
newListItem.classList.add('todo-item');

let deleteButton = document.createElement('button');
deleteButton.classList.add('button-delete');
deleteButton.innerHTML = 'X';
deleteButton.setAttribute('onclick', 'deleteItem(this)');

newListItem.appendChild(deleteButton);

let itemPElement = document.createElement('span');
itemPElement.innerHTML = newItemText;

newListItem.appendChild(itemPElement);

todoList.appendChild(newListItem);
}

function deleteItem(item) {
console.log(item.parentElement);

item.parentElement.remove();
}
</script>

0 comments on commit b08203f

Please sign in to comment.