Search code examples
jqueryjquery-selectorsattrclosest

JQuery Change Next Table Attribute


I am trying to change the next tables attribute after the font tag with class .rewardpoints. Every time I try the following code It changes the cellpadding to 5 on the table ABOVE .rewardpoints. Any ideas?

<table cellspacing="0" cellpadding="0" border="0">
     <tbody><tr>
        <td>
        <font></font>
        <font></font>
        <font class="text colors_text rewardpoints"><span>Earn Burkett Bucks</span></font>
             <table width="100%" cellspacing="0" cellpadding="10" border="0">
               <tbody>
                 <tr>
                   <td>
                   </td>
                 </tr>
              </tbody>
             </table>
        </td>
    </tr></tbody>
</table>

jQuery('.rewardpoints').closest('table').attr('cellpadding', '5');

I have also tried the following:

jQuery('.rewardpoints').next('table').attr('cellpadding', '5');
jQuery('.rewardpoints').nextAll('table').attr('cellpadding', '5');
jQuery('.rewardpoints').siblings('table').attr('cellpadding', '5');

Solution

  • Closest travels up the DOM tree.

    Begins with the current element Travels up the DOM tree until it finds a match for the supplied selector

    You should use siblings, or next, or nextAll