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.
- <table>
- <tr>
- <td>
- <div class="level1">11</div>
- <table>
- <tr>
- <td>
- <div class="level2">++22</div>
- </td>
- </tr>
- <tr>
- <td>
- <div class="level2">++22</div>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- <table>
- <tr>
- <td>
- <div class="level1">AA</div>
- <table>
- <tr>
- <td>
- <div class="level2">++BB</div>
- </td>
- </tr>
- <tr>
- <td>
- <div class="level2">++BB</div>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
My failed attempt:
- $('.level1').each(function(index){
- $(this).find(".level2").css('background-color', 'red');
- });
Can anyone help? Am I even on the right track?
Thank you,
John