JayDee JayDee - 3 months ago 11x
Javascript Question

How to increment a numeric string by +1 with Javascript/jQuery

I have the following variable:

pageID = 7

I'd like to increment this number on a link:

$('#arrowRight').attr('href', 'page.html?='+pageID);

So this outputs 7, I'd like to append the link to say 8. But if I add +1:

$('#arrowRight').attr('href', 'page.html?='+pageID+1);

I get the following output: 1.html?=71 instead of 8.

How can I increment this number to be pageID+1?


Try this:

parseInt(pageID, 10) + 1

Accordint to your code:

$('#arrowRight').attr('href', 'page.html?='+ (parseInt(pageID, 10) + 1));