Estoy tratando de filtrar una tabla usando una función de JavaScript, pero no estoy seguro de cuál es el problema... Al hacer clic en el enlace del filtro, no sucede nada, pero debería estar filtrando la segunda columna (columna "Plataforma") y solo muestra filas con "PRUEBA" en él.
Estoy tratando de depurarlo aquí:
https://jsfiddle.net/7vh5wmsx/
function filterTable(input) { var filter = input.value.toUpperCase(); var table = document.getElementById("myTable"); var tr = table.getElementsByTagName("tr"); var tds = tr.getElementsByTagName('td'); for (var i = 0; i < tr.length; i++) { if (tds[1].textContent.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } }Usa este código
function myFunction() { // Declare variables var input, filter, table, tr, td, i, txtValue; input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); // Loop through all table rows, and hide those who don't match the search query for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[0]; if (td) { txtValue = td.textContent || td.innerText; if (txtValue.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } }