Guys how to get the value of columns and display them in alert (); Help and I suffer in any way ((((I use jQuery

<table class="employeeTable" border="1"> <thead> <tr> <th class="employeeTableHeader" scope="col">Name</th> <th class="employeeTableHeader" scope="col">Department</th> <th class="employeeTableHeader" scope="col">Age</th> <th class="employeeTableHeader" scope="col">Salary</th> </tr> </thead> <tbody> <tr class="employeeTableOddRow"> <td> John </td> <td> Marketing </td> <td> 30 </td> <td> 2000.0 </td> </tr> <tr class="employeeTableEvenRow"> <td> Robert </td> <td> Marketing </td> <td> 35 </td> <td> 3000.0 </td> </tr> <tr class="employeeTableOddRow"> <td> Mark </td> <td> Sales </td> <td> 25 </td> <td> 2500.0 </td> </tr> <tr class="employeeTableEvenRow"> <td> Chris </td> <td> Marketing </td> <td> 33 </td> <td> 2500.0 </td> </tr> <tr class="employeeTableOddRow"> <td> Peter </td> <td> Customer Care </td> <td> 20 </td> <td> 1500.0 </td> </tr> </tbody> </table> 

Thank you and with the coming!

  • why do you need jquery for this? ru.stackoverflow.com/a/557282/191482 - Alexey Shimansky
  • one
    @ Alexey Shimansky, probably because for such primitive tasks jq was invented! - HamSter
  • one
    @Elena but in the case of running through the columns there is no difference .. and there and there cycle. number of rows rows.length and all. Especially if this is the only task at all ... - Alexey Shimansky

1 answer 1

eg:

 $('td').each(function(){ console.log($(this).html()); alert($(this).html()); }); 
 <script src="https://code.jquery.com/jquery-2.0.3.js"></script> <table class="employeeTable" border="1"> <thead> <tr> <th class="employeeTableHeader" scope="col">Name</th> <th class="employeeTableHeader" scope="col">Department</th> <th class="employeeTableHeader" scope="col">Age</th> <th class="employeeTableHeader" scope="col">Salary</th> </tr> </thead> <tbody> <tr class="employeeTableOddRow"> <td> John </td> <td> Marketing </td> <td> 30 </td> <td> 2000.0 </td> </tr> <tr class="employeeTableEvenRow"> <td> Robert </td> <td> Marketing </td> <td> 35 </td> <td> 3000.0 </td> </tr> <tr class="employeeTableOddRow"> <td> Mark </td> <td> Sales </td> <td> 25 </td> <td> 2500.0 </td> </tr> <tr class="employeeTableEvenRow"> <td> Chris </td> <td> Marketing </td> <td> 33 </td> <td> 2500.0 </td> </tr> <tr class="employeeTableOddRow"> <td> Peter </td> <td> Customer Care </td> <td> 20 </td> <td> 1500.0 </td> </tr> </tbody> </table> 

  • Helen, thank you very much a Happy New Year! - elik
  • I wish you happiness, love and all the best from the heart - elik
  • @elik, Thanks !!! And you all the best in the new year !!! - HamSter