This is the main requirement. We take the search text from the input,
convert it to lowercase, and compare it with each cell's text. If at least
one cell matches, we show the row. If no cell matches, we hide the row.
function applySearch() {
const keyword = searchInput.value.trim().toLowerCase();
const rows = getRows();
rows.forEach(row => {
const tds = row.querySelectorAll("td");
let match = false;
tds.forEach(td => {
const text = td.textContent.toLowerCase();
if (keyword && text.includes(keyword)) {
match = true;
}
});
if (!keyword || match) {
row.style.display = "";
} else {
row.style.display = "none";
}
});
}
Notice the condition:
if (!keyword || match).
This means: if the box is empty, show everything. Otherwise, only show matching rows.
If you forget to reset hidden rows when the search box becomes empty,
some rows may stay hidden. That is why the empty-search condition matters.