I see two options here
var link = $('a').attr('href');
var equalPosition = link.indexOf('='); //Get the position of '='
var number = link.substring(equalPosition + 1); //Split the string and get the number.
I dont know if you're gonna use it for paging and have the text in the <a>
-tag as you have it, but if you should you can also do
var number = $('a').text();
Here's a method that works by transforming the querystring into JSON...
var link = $('a').attr('href');
if (link.indexOf("?") != -1) {
var query = link.split("?")[1];
eval("query = {" + query.replace(/&/ig, "\",").replace(/=/ig, ":\"") + "\"};");
if (query.page)
alert(unescape(query.page));
else
alert('No page parameter');
} else {
alert('No querystring');
}
I'd go with a library like the others suggest though... =)
Use this jQuery extension by James Padoley
if ($('a').on('Clicked').text().search('1') == -1)
{
//Page == 1
}
else
{
//Page != 1
}
First of all you need to extract the path with something like this:
$("a#myLink").attr("href");
Then take a look at this plugin: http://plugins.jquery.com/project/query-object
It will help you handle all kinds of querystring things you want to do.
/Peter F
The first thing that comes to my mind is a one-liner regex:
var pageNum = $("#specificLink").attr("href").match(/page=([0-9]+)/)[1];