I'm studying javascript and developing an All List .
The only thing I want to do is to add elements to a <ul>
and then to enable them to click
so that they only change class.
My html
is very simple ... This js
is already a zone because I tried everything and nothing works ...
var addBtn = document.querySelector("button");
var inputText = document.getElementsByTagName("input").value;
var inputT = document.getElementById("addLista");
var listaCompleta = document.querySelector("#listaCompleta");
var itensLista = document.getElementsByClassName("notDone");
function updateLista (lista){
return lista
}
var listaOk = updateLista(itensLista)
addBtn.addEventListener("click", function () {
var liAdd = document.getElementById("addLista").value;
if (liAdd !== "") {
var liNova = document.createElement("li");
liNova.textContent = liAdd;
liNova.classList.add("notDone");
listaCompleta.appendChild(liNova);
liLength = itensLista.length
console.log(liLength);
itensLista = document.getElementsByTagName("li");
}
inputT.value = "";
listaOk = updateLista(itensLista)
});
function click (listaOk){
for( var i = 0; i <= listaOk.length; i++){
if(listaOk[i]){
listaOk[i].addEventListener("click", function(){
this.classList.toggle("done");
})
}
}
}
click(listaOk);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link type ="text/css" rel="stylesheet" href="todoStyle.css">
<title>Todo Dom</title>
</head>
<body>
<h1>Todo List</h1>
<div class="central">
<form action="">
Adicione um Item: <input type="text" id="addLista" name="addLista"> <button type="button">add</button></form>
<ul id="listaCompleta">
</ul>
</div>
<script type="text/javascript" src="todoJs.js"></script>
</body>
</html>
Thanks!