0

I want to click on a pagination link at the bottom which is the next to <td class="cur">. In this case, "Pg 2".

<td class="cur"><a aria-label="Pg 1" class="pg" href=""></a></td>
<td><a aria-label="Pg 2" class="pg" href=""></a></td>

Then again on Page 2, click on a link which is the next to <td class="cur">. In this case, "Pg 3".

<td><a aria-label="Pg 1" class="pg" href=""></a></td>
<td class="cur"><a aria-label="Pg 2" class="pg" href=""></a></td>
<td><a aria-label="Pg 3" class="pg" href=""></a></td>

and so on.

How do I implement this in JavaScript/jQuery?

CuriousDev
  • 1,255
  • 1
  • 21
  • 44

1 Answers1

0

Assuming that your table has an ID ('tableName'), this should work fine:

var nextButton= $('#nav td.cur > a.pg')
               .parent() // go to the parent td
               .next() // vist next td sibling
               .find('a.pg'); // find a inside of this td sibling
    nextButton.trigger('click');

You can find examples of trigger method in this post.

Beri
  • 11,470
  • 4
  • 35
  • 57
  • If my table has a tbody and a tr containing all these td's, does the selector change? I tried the above, gave it the table id but nothing happens. I even tried this alert($('#nav td.cur > a.pg').attr('href')); which returned undefined. – CuriousDev Sep 30 '18 at 16:10