Using Find with an Each

Using Find with an Each


Hello!

I'd like to change the background color of the div.level2

I'm trying to use the each and the find statement to accomplish this but I can't seem to get the desired results.


  1. <table>
  2.     <tr>
  3.         <td>
  4.             <div class="level1">11</div>
  5.             <table>
  6.                 <tr>
  7.                     <td>
  8.                         <div class="level2">++22</div>
  9.                     </td>
  10.                 </tr>
  11.                 <tr>
  12.                     <td>
  13.                         <div class="level2">++22</div>
  14.                     </td>
  15.                 </tr>
  16.             </table>
  17.         </td>
  18.     </tr>
  19. </table>
  20. <table>
  21.     <tr>
  22.         <td>
  23.             <div class="level1">AA</div>
  24.             <table>
  25.                 <tr>
  26.                     <td>
  27.                         <div class="level2">++BB</div>
  28.                     </td>
  29.                 </tr>
  30.                 <tr>
  31.                     <td>
  32.                         <div class="level2">++BB</div>
  33.                     </td>
  34.                 </tr>
  35.             </table>
  36.         </td>
  37.     </tr>
  38. </table>


My failed attempt:

  1. $('.level1').each(function(index){

  2.       $(this).find(".level2").css('background-color', 'red');
  3. });
Can anyone help? Am I even on the right track?

Thank you,
John