Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
¿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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!