garrip91,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>to-do list</title>
<style type="text/css">
* {
box-sizing: border-box;
}
ul {
margin: 0;
padding: 0;
}
ul li {
cursor: pointer;
position: relative;
padding: 12px 8px 12px 40px;
background: #eee;
font-size: 18px;
transition: .2s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
ul li:nth-child(even) {
background: yellow;
}
ul li:nth-child(odd) {
background: sandybrown;
}
ul li:hover {
background: magenta;
}
ul li:hover::before {
content: '\27A4';
position: absolute;
top: 10px;
left: 16px;
height: 15px;
width: 7px;
}
ul li.checked {
background: lime;
color: #fff;
text-decoration: underline;
}
ul li.checked::before {
content: '';
position: absolute;
border-color: #fff;
border-style: solid;
border-width: 0 2px 2px 0;
top: 10px;
left: 16px;
transform: rotate(45deg);
height: 15px;
width: 7px;
}
.close {
position: absolute;
right: 0;
top: 0;
padding: 12px 16px 12px 16px;
}
.close:hover {
background-color: red;
color: white;
}
.header {
background-color: aqua;
padding: 30px 40px;
color: purple;
text-align: center;
}
.header:after {
content: '';
display: table;
clear: both;
}
input {
margin: 0;
border: none;
border-radius: 0;
width: 75%;
padding: 10px;
float: left;
font-size: 16px;
}
.addBtn {
padding: 10px;
width: 25%;
background: #d9d9d9;
color: #555;
float: left;
text-align: center;
font-size: 16px;
cursor: pointer;
transition: .3s;
border-radius: 0;
}
.addBtn:hover {
background-color: #bbb;
}
</style>
</head>
<body>
<div id="myDIV" class="header">
<h1>Tips on how to correctly create your to-do list:</h1>
<input type="text" id="myInput" placeholder="Here you can offer your option(as a recommendation)...">
<span class="addBtn">Add</span>
</div>
<ul id="myUL">
<li>Choose a carrier at a distance of the hand, which should often "loom" before your eyes</li>
<li>Select the same time for its creation: morning or evening</li>
<li>Make up for the current day only</li>
<li>Prioritize</li>
<li>Keep a "list of ideas"</li>
<li>Supervise the "kidnappers of time"</li>
<li>Be realistic</li>
<li>Plan a vacation</li>
<li>Do not "execute" yourself ...</li>
</ul>
<script>
var list = document.getElementById("myUL");
var input = document.getElementById("myInput");
var addBtn = document.querySelector(".addBtn");
function createClose(parent) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00d7");
span.className = "close";
span.appendChild(txt);
span.addEventListener("click", function() {
list.removeChild(parent)
}, false);
parent.appendChild(span)
}
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) createClose(myNodelist[i]);
list.addEventListener("click", function(ev) {
if (ev.target.tagName === "LI") ev.target.classList.toggle("checked")
}, false);
function newElement() {
var li = document.createElement("li");
var inputValue = input.value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === "") alert("You must write something!");
else {
list.appendChild(li);
createClose(li)
}
input.value = ""
}
input.addEventListener("keypress", function(ev) {
if (ev.keyCode === 13) newElement()
}, false);
addBtn.addEventListener("click", newElement, false);
</script>
</body>
</html>