Guest User

Untitled

a guest
Aug 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. Collecting data with jQuery from a table
  2. <table>
  3. <thead>
  4. <tr>
  5. <th></th>
  6. <th>Name</th>
  7. <th>Email</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <td class='checkinput'>
  13. <input type="checkbox" name="names" value="MD5_HASH"/>
  14. </td>
  15. <td>
  16. John Doe
  17. </td>
  18. <td>
  19. email@mail.com
  20. </td>
  21. </tr>
  22. <!-- etc. -->
  23. </tbody>
  24. </table>
  25.  
  26. $("tr").click(function() {
  27. var $checkbox = $(this).find(":checkbox");
  28. $checkbox.attr('checked', !$checkbox.attr('checked'));
  29. });
  30.  
  31. $("tr").click(function(e) {
  32. if ($(e.target).is(':checkbox')) return;
  33. var $checkbox = $(this).find(":checkbox");
  34. $checkbox.attr('checked', !$checkbox.attr('checked'));
  35. });
  36.  
  37. var emails = [];
  38. $("table tbody tr:has(input:checkbox:checked)").each(function(){
  39. emails.push( $('td.email', $(this)).text() );
  40. });
  41.  
  42. $("tr).click(function(e) {
  43. if (e.target.id==xxx) // if ($('#'+e.target.id).attr('class')=='classssss') ...
  44. ....
  45.  
  46.  
  47. });
  48.  
  49. $(".table tr:gt(0)").each (
  50.  
  51. function () {
  52.  
  53. alert($('td:eq(2)',$(this)).text());
  54.  
  55. }
  56. );
Add Comment
Please, Sign In to add comment