Todo list using html css and js



TO DO LIST




 <html><head>
   </head>

<body>
<h2 style="margin:25px"> To <sub style="color:black"> Do<sub style="color:snow"> List</h2></sub></sub>
<div class="content">
<div id="myDIV" class="header">



<input type="text" id="myInput" placeholder="Title......">

<span onclick="newElement()" class="addBtn">Add</span>

</div>


<ul id="myUL">

  <li>Hit the gym</li>
  <li class="checked">Pay bills</li>
  <li>Clean the Car</li>
  <li>Buy Groceries</li>
  <li>Read a book</li>
  <li>Organize Home</li>

</ul>

</div>
<script>



var myNodelist = document.getElementsByTagName("LI");

var i;
for(i=0; i < myNodelist.length;i++){
var span=document.createElement("SPAN");

var txt=document.createTextNode("\u00D7");

span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}


var close = document
.getElementsByClassName("close");
var i;

for(i=0; i < close.length;i++){
  close[i].onclick = function() {
    var div = this.parentElement;
    div.style.display = "none";
  }
}



var list=document.querySelector('ul');
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=document.getElementById("myInput").value;

var t = document.createTextNode(inputValue);

li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
  } else {
    document.getElementById("myUL").appendChild(li);
  }
  document.getElementById("myInput").value = "";

var span=document.createElement("SPAN");

var txt=document.createTextNode("\u00D7");

  span.className = "close";
  span.appendChild(txt);
  li.appendChild(span);

for (i = 0; i < close.length; i++) {
    close[i].onclick = function() {
      var div = this.parentElement;
      div.style.display = "none";
    }
  }
}

</script>

</body>
</html>
                    
                  
                



 body {
  margin: 0;
  min-width: 250px;
  background-image:linear-gradient(to left,khaki,darkslategray);
  height:100%;

}

.content{
    margin:30px 0px 0px 0px;
    border-radius: 20px;
 box-shadow: 0px 0px 50px black;
}
ul {
  margin: 0;
  padding: 0;
}


ul li {
  list-style-type:none;
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  background: #eee;
  font-size: 18px;
  transition: 0.2s;

  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}



ul li:nth-child(odd) {
  background: #f9f9f9;
}



ul li:hover {
  background: #ddd;
}


ul li.checked {
  background: powderblue;
  color:navy;
  text-decoration: line-through;
}



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: #f44336;
  color: white;
}


.header {
  background-image:linear-gradient(to bottom right,#404cb1,#E91E63,#00b9ff);
  padding: 30px 40px;
  color: white;
  text-siz:80px;
  text-align: center;
}


.header:after {
  content: "";
  display: table;
  clear: both;

}



input {
  border: none;
  border-radius: 30px;
  width: 70%;
  padding: 10px;
  float: left;
  font-size: 16px;
  box-sizing: border-box;


}

h2{
  color:gold;
  text-align:center;
  font-size:50px;
}

.addBtn {
  padding: 10px;
  box-sizing: border-box;
   border-radius: 30px;
   position:relative;
   right:-165px;
  width: 15%;
  background-color:black;
  color:aqua;
  float: left;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
  transition: 0.3s;
}

.addBtn:hover {
  background-color:black;
  color:snow;
  font-size:105%;
}