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

219
Views
Cómo ordenar varias tablas con jQuery

Quiero ordenar todos los valores, pero jquery ordena solo tres valores. Quiero ordenar varias tablas en la etiqueta h2, pero cuando lo ordeno, solo ordeno los primeros 3 valores, pero quiero todos los valores.

 $('#alphBnt').on('click', function() { var sorting = $(".box").sort(function(a, b) { return $(a).find("h2").text() > $(b).find("h2").text(); }); $("#container").html(sorting) });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <p><button id="alphBnt">Sort</button></p> <div id="container"> <table border=2px class="box"> <tr> <td class="name"> <h1>mui</h1> </td> <td class="number"> <h2>4512</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>oinecellars</h1> </td> <td class="number"> <h2>566</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>zacchus </h1> </td> <td class="number"> <h2>34566</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>zacchus </h1> </td> <td class="number"> <h2>1</h2> </td> </tr> </table> </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesitas usar - :

 $('#alphBnt').on('click', function() { var sorting = $(".box").sort((a, b) => $(a).find("h2").text() - $(b).find("h2").text()).appendTo("#container") });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <p><button id="alphBnt">Sort</button></p> <div id="container"> <table border=2px class="box"> <tr> <td class="name"> <h1>mui</h1> </td> <td class="number"> <h2>4512</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>oinecellars</h1> </td> <td class="number"> <h2>566</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>zacchus </h1> </td> <td class="number"> <h2>34566</h2> </td> </tr> </table> <table border=2px class="box"> <tr> <td class="name"> <h1>zacchus </h1> </td> <td class="number"> <h2>1</h2> </td> </tr> </table> </div>

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!