I am new to JQuery.
If I have the following tag. What is the best JQuery method to extract the value for "page" from the href.
<a href="Search/Advanced?page=2">2</a>
Malcolm
The first thing that comes to my mind is a one-liner regex:
var pageNum = $("#specificLink").attr("href").match(/page=([0-9]+)/)[1];
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With