Вот вам
Примечание. Я дал столу thead / tbody и переместил ID
window.addEventListener("load", function() {
document.getElementById("myInput").addEventListener("input", function() {
const val = this.value.trim().toUpperCase();
const filter = new RegExp('\\b' + val + '\\b'); // word boundary regex
const trs = document.querySelectorAll("#myTable tr");
for (let i = 0; i < trs.length; i++) {
trs[i].style.display = val ? "none" : "";
const tds = trs[i].querySelectorAll("td");
found = false;
for (let j = 0; j < tds.length; j++) {
const text = tds[j].textContent.toUpperCase();
if (filter.test(text)) found = true;
}
if (found) trs[i].style.display = "";
}
})
})
<input type="text" id="myInput" autocomplete="off" placeholder="Search for names.." title="Type in a name" />
<table>
<thead>
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Country</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>John Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Johnaton snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Johnny Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Johnea Essen</td>
<td>Germany</td>
</tr>
<tr>
<td>Jon Bacchus Winecellars</td>
<td>Canada</td>
</tr>
<tr>
<td>Jonny Alimentari Riuniti</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>UK</td>
</tr>
<tr>
<td>Paris specialites</td>
<td>France</td>
</tr>
</tbody>
</table>
Только для имен:
window.addEventListener("load", function() {
document.getElementById("myInput").addEventListener("input", function() {
const val = this.value.trim().toUpperCase();
const filter = new RegExp('\\b' + val + '\\b'); // word boundary regex
const trs = document.querySelectorAll("#myTable tr");
for (let i = 0; i < trs.length; i++) {
const text = trs[i].querySelector("td").textContent.toUpperCase(); // or td:first-child
trs[i].style.display = filter.test(text) ? "" : "none"
}
})
})
<input type="text" id="myInput" autocomplete="off" placeholder="Search for names.." title="Type in a name" />
<table>
<thead>
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Country</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>John Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Johnaton snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Johnny Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Johnea Essen</td>
<td>Germany</td>
</tr>
<tr>
<td>Jon Bacchus Winecellars</td>
<td>Canada</td>
</tr>
<tr>
<td>Jonny Alimentari Riuniti</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>UK</td>
</tr>
<tr>
<td>Paris specialites</td>
<td>France</td>
</tr>
</tbody>
</table>