rlemon
rlemon

Reputation: 17666

JQuery pagination plugin showing strange results

I am building a pagination plugin and I am having the strangest results. here is a demo

If you click on the next button (>>) you will be taken to the last page. But, if you click on the prev button (<<) before you click on the next button you will be taken to the proper page.

Ohh, and if you click on a page number then the next button you will always be taken to the last page.

I've been staring at it for a bit now. boggles me.

Upvotes: 1

Views: 110

Answers (1)

Paul
Paul

Reputation: 141829

It's because this line return a string:

 var _to = $(this).attr("id");

So that string eventually makes it's way into current_to and when you write current_to + $options.items_pp you get a string like 1010 instead of 20.

Just change the line to:

var _to = parseInt($(this).attr("id"), 10);

Or even better:

var _to = parseInt(this.id, 10);

JSFiddle

Upvotes: 1

Related Questions