Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
¿Cómo buscar el número de la tabla html usando javascript?

Tengo dificultades para buscar números en la tabla HTML usando javascript. Lo que quiero hacer, si ingreso 500, los resultados deberían ser 500 y números que también son mayores que 500. Revisé otras preguntas de StackOverflow pero no se responde como esperaba. ¿Alguien puede ayudarme, por favor?

 function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(textValue >= filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } }
 <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> <table id="myTable"> <tr class="header"> <th style="width:60%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Un pequeño cambio en tu código.

 if(+textValue >= +filter )

Comparar valores como número en lugar de cadenas

 function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(+textValue >= +filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } }
 <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> <table id="myTable"> <tr class="header"> <th style="width:60%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda