I'm trying to make a very simple "to-do" list application. But I'm having trouble moving my list items from the "To-do" list, to the "Done" list.
Any help would be very appreciated.
This is my code so far.
HTML
<html>
<head>
<script src="js/main.js"></script>
<link rel="stylesheet" href="css/css.css">
<title>Inlämingsuppgift</title>
</head>
<body>
<input type="text" id="input" placeholder="Add a to-do"></input> <button onclick="addToDo()">Add</button>
<h1>To do</h1>
<ul id="list1">
</ul>
<h1>Done</h1>
<ul id="list2">
</ul>
</body>
JS
function addToDo() {
var input = document.getElementById("input").value + " ";
var list = document.getElementById("list1");
var li = document.createElement("li");
li.className = "selected";
var doneButton = document.createElement("button");
doneButton.innerHTML = "Done";
doneButton.onclick = moveToDo;
doneButton.className = "move";
li.appendChild(document.createTextNode(input));
li.appendChild(doneButton);
list.appendChild(li);
}
function moveToDo() {
document.querySelector('.move').click(function() {
document.querySelector('#list2').insertAdjacentHTML("beforeend",'<li>', document.querySelector('#list1 .selected').text(), '</li>');
document.querySelector('#list1 .selected').remove();
});
}