I am making a script that cleans the following 3 elements. Home
In If the clause has to fall into the true (I made the query through console.log and have to fall into the true one, however 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>