1
I am making a script that clears the following 3 elements.
In If the clause has to fall into the true one (I made the query through the console.log and have to fall into the true one, but it falls into the false position.
Can you help me figure out why??
function teste(){
var idAntigo = "123"
var tds = document.querySelectorAll("#tblItens td");
var values = [];
var tabela = document.querySelector("#tblItens");
var TDs1 = tabela.getElementsByTagName("td");
console.log("Caiu aqui");
for (i = 0; i < TDs1.length; i++) {
console.log("Aqui também");
if (TDs1[i].innerHTML === idAntigo ) {
console.log("Aqui não");
TDs1[i].innerHTML = "";
TDs1[i + 1].innerHTML = "";
TDs1[i + 2].innerHTML = "";
TDs1[i + 3].innerHTML = "";
break;
} else { console.log("false")}
}
}
<html>
<body>
<table id="tblItens">
<tr>
<td> 123 </td>
<td> 124 </td>
<td> 123 </td>
</tr>
<td> 123 </td>
<tr>
<td> 125 </td>
<td> 124 </td>
</tr>
</table>
<button onclick="teste()"> teste </button>
</body>
</html>
(Tds1[i]. innerHTML === Tds1) will never be true, you are comparing the current td with the object that stores all tds, what you really want to do in this part?
– Felipe Duarte
Sorry @Felipe, the comparison should compare the td element with the
idAntiga
, still even falls in the If, corrected the question there, pardon again– Sora
Ata understood your problem
– Felipe Duarte