Advertisement
LucianoCharles2017

checkboxes em tabelas diferentes

Oct 5th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.66 KB | None | 0 0
  1. <style>
  2.     table {
  3.         font-family: arial, sans-serif;
  4.         border-collapse: collapse;
  5.         width: 100%;
  6.     }
  7.  
  8.     td, th {
  9.         border: 1px solid #dddddd;
  10.         text-align: left;
  11.         padding: 8px;
  12.     }
  13.  
  14.     tr:nth-child(even) {
  15.         background-color: #dddddd;
  16.     }
  17. </style>
  18.  
  19. <table id="tabela1">
  20.     <thead>
  21.         <tr>
  22.             <th><input type="checkbox" class="checkTodos" name="checkTodos">Selecionar Todos</th>
  23.             <th>Nome</th>
  24.             <th>E-mail</th>
  25.         </tr>
  26.     </thead>
  27.     <tbody>
  28.         <tr>
  29.             <td><input type="checkbox" value='' name=""/></td>
  30.             <td>Fulano de Tal</td>
  31.             <td>[email protected]</td>
  32.         <tr>
  33.             <td><input type="checkbox" value='' name=""/></td>
  34.             <td>Ciclano</td>
  35.             <td>[email protected]</td>
  36.         </tr>
  37.      </tbody>
  38. </table>
  39.  
  40. <table id="tabela2">
  41.     <thead>
  42.     <tr>
  43.         <th><input type="checkbox" class="checkTodos" name="checkTodos">Selecionar Todos</th>
  44.         <th>Nome</th>
  45.         <th>E-mail</th>
  46.     </tr>
  47.     </thead>
  48.     <tbody>
  49.     <tr>
  50.         <td><input type="checkbox" value='' name=""/></td>
  51.         <td>Beltrano de Tal</td>
  52.         <td>[email protected]</td>
  53.     <tr>
  54.         <td><input type="checkbox" value='' name=""/></td>
  55.         <td>Pafuncio</td>
  56.         <td>[email protected]</td>
  57.     </tr>
  58.     </tbody>
  59. </table>
  60.  
  61.  
  62.  
  63. <script>
  64.     $(".checkTodos").click(function () {
  65.  
  66.         let tabela = $(this)[0]['offsetParent']['offsetParent']['id'];
  67.  
  68.         $("#"+tabela).find('input:checkbox').prop('checked', $(this).prop("checked"));
  69.        
  70.     });
  71. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement