I don't answer your question directly, but I can suggest another approach.
You can create simple fields in which you will contain new offset. Or you can store offset directly on elements next
and prev
, e.g.
<a href='#' id='0' class='goPrev'>Previous</a>
and
<a href='#' id='3' class='goNext'>Next</a>
Default offset is zero. For next button offset will be 3, for previous null (and user can't click on prev button).
When user will click next
button, you will do your ajax request and update both fields. goNext field will have offset 6 and previous will have offset 0.
When user will click next
button again, you will do your ajax request again and update both fields again. goNext field will have offset 9 and previous will have offset 3.
Etc etc etc.
Also, you can store data in hidden inputs.
Hope, this will help.