Advertisement
trentjs

add class to parent

Dec 11th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5.  
  6.    
  7. body{
  8.     font-family: Arial, Helvetica, sans-serif;
  9. }
  10.  
  11. .tableClean {
  12.   border-collapse: collapse;
  13.   color:#555555;
  14. }
  15.  
  16. .tableClean tr{
  17.     border-left: 1px solid #cccccc;
  18.     border-right: 1px solid #cccccc;
  19. }
  20.  
  21. .tableClean tr:last-child{
  22.     border-bottom: 1px solid #cccccc;
  23. }
  24.  
  25. .tableClean tr:first-child{
  26.     border-top: 1px solid #cccccc;
  27.     background-color: #cccccc;
  28. }
  29.  
  30. .tableClean td, .tableClean th{
  31.     padding:0.75em;
  32. }
  33.  
  34. .tdBlue{
  35.     color:#000055;
  36.     background-color: cornflowerblue;
  37. }
  38.  
  39. .trGreen{
  40.     color:#005500;
  41.     background-color: darkseagreen;
  42. }
  43.  
  44. </style>
  45. </head>
  46. <body>
  47.  
  48. <table class="tableClean">
  49.   <tr>
  50.     <th>Header A</th>
  51.     <th>Header B</th>
  52.     <th>Header C</th>
  53.   </tr>
  54.   <tr>
  55.     <td>Content 1a</td>
  56.     <td>Content 1b</td>
  57.     <td class="tdBlue">.tdBlue</td>
  58.   </tr>
  59.   <tr>
  60.     <td>Content 2a</td>
  61.     <td>Content 2b</td>
  62.     <td>Content 2c</td>
  63.   </tr>
  64. </table>
  65.  
  66. <script>
  67.  
  68. var thisSourceList = document.querySelectorAll(".tdBlue");
  69. for(var i = 0; i < thisSourceList.length; i++) {
  70.     thisSourceList[i].parentNode.classList.add("trGreen");
  71. }
  72.  
  73. </script>
  74.  
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement