I have the following codes. table filter value
Problem: when un-check all filter and checked 1 2 again it show all value .
when checked 1 2 I want to show just col1 value = 1 and col2 value = 2
Can anyone advise with my code ?
Result #
What I Need #
function filter(event, filterCol) {
let element = event.target;
let condt1 = document.getElementsByClassName(filterCol);
for (let i = 0; i < condt1.length; i++) {
if (condt1[i].innerHTML.toLocaleUpperCase() == element.value.toLocaleUpperCase()) {
if (element.checked == true) {
condt1[i].parentElement.closest('tr').style = "display:table-row"
} else {
condt1[i].parentElement.closest('tr').style = "display:none"
}
}
}
}
document.querySelectorAll('.option1').forEach(input => input.addEventListener('input', ()=>filter(event,"check1")));
document.querySelectorAll('.option2').forEach(input => input.addEventListener('input', ()=>filter(event,"check2")));
document.querySelectorAll('.option3').forEach(input => input.addEventListener('input', ()=>filter(event,"check3")));
<div id="input">
<label>Filter Number </label><br>
<label>1<input class="option1" type="checkbox" value="1" checked/></label>
<label>2<input class="option2" type="checkbox" value="2" checked/></label>
<label>3<input class="option3" type="checkbox" value="3" checked/></label>
</div><br>
<table id="listingTable">
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
<tr>
<td class="check1">1</td>
<td class="check2">4</td>
<td class="check3">3</td>
</tr>
<tr>
<td class="check1">1</td>
<td class="check2">2</td>
<td class="check3">5</td>
</tr>
<tr>
<td class="check1">3</td>
<td class="check2">2</td>
<td class="check3">3</td>
</tr>
<tr>
<td class="check1">2</td>
<td class="check2">2</td>
<td class="check3">3</td>
</tr>
<tr>
<td class="check1">4</td>
<td class="check2">6</td>
<td class="check3">3</td>
</tr>
</table>
Sorry for my bad English, can't explain all what I need, hope you understand what I need
Thanks.

