I have a structure like this
<ul id="nomes">
<li class="classli">
<div class="Nome">Pedro</div>
<div class="data">13/09/2017</div>
<input class="check" type="checkbox">
</li>
<li class="classli">
<div class="Nome">Lucas</div>
<div class="data">13/09/2017</div>
<input class="check" type="checkbox">
</li>
</ul>
I'm using this JS to generate ul / li
var obj = JSON.parse(req.responseText);
document.getElementById("tabLista").innerHTML = "";
var mydiv = document.getElementById("tabLista");
var minhaul = document.createElement("ul");
minhaul.setAttribute("id", "sul");
var novali = document.createElement("li");
var novadivtipo = document.createElement("div");
var novadivnome = document.createElement("div");
var novadivtamanho = document.createElement("div");
var novocheckbox = document.createElement("input");
novali.setAttribute("class", "classli");
novadivtipo.setAttribute("class", "tipo");
novadivtipo.setAttribute("id", "Tipo" + R);
novadivnome.setAttribute("class", "nomediv");
novadivtamanho.setAttribute("class", "tamanhodiv");
novocheckbox.setAttribute("class", "checkdelete");
novocheckbox.setAttribute("type", "checkbox");
img.setAttribute("class", "Icon");
novadivtipo.appendChild(img);
novali.setAttribute("id", (obj.Lista[R].Nome));
novali.appendChild(novadivtipo);
novali.appendChild(novadivnome);
novali.appendChild(novadivtamanho);
novali.appendChild(novocheckbox);
minhaul.appendChild(novali);
mydiv.appendChild(minhaul);
My json I'm using to generate html
{
"d": "api",
"Lista": [
{
"Data": "12/12/2017",
"Nome": "Lucas"
}
],
"arq": "3",
"pasta": "5"
}
I want to click on the checkbox of each li and send the value of each name to an array and change the background of the li to another color, and when the checkbox is unchecked remove it from the array, I found the solution only with jquery, but I'd like some help solving this problem only with pure js.
Thanks for the help:)