1
I have a structure just 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 am 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 read and send the value of each name to an array and change the background of the read to another color, and when the checkbox is unchecked remove the same from the array, I found the solution only with jquery, but I would like a help to solve this problem only with pure js.
Thanks for the help :)
How are you generating this HTML? Maybe you can do this more reactively than reading HTML in the DOM.
– Sergio
Hello, I am recovering the data by a json and putting it through a createelement and setAttribute.
– Stan
Okay, so there’s a more interesting way to do this :) You can put this code that inserts these
ul
/li
?– Sergio
I can yes, a moment
– Stan
Both
Pedro
andLucas
come from the same JSON? or you have a json per element? I think I’m remembering another question from you... would you fetch the data one by one? then you have somewhere an arrays of jsons?– Sergio
Pedro and Lucas come from the same JSON, the other question was related to this, the other I wanted to make a multi delete based on that list of names in each read, ai como eu clique na checkbox esse nome vai ser enviado para a função de multi delete, mais ou menos assim.
– Stan
Ok, so JSON is an array of objects and when it is unchecked each checkbox you want to call a function and when it is checked call another function, and at the same time an array (JSON copy type) with the selected data (or this last array is not needed?)?
– Sergio
Json is an array of objects, when the person marks the checkbox of li I want the background to change color to give the effect of selected, and send the person’s name to an array (to use later in the function of the other question)and when unchecked the person’s name will exit that array.
– Stan