Reputation: 75
i want to extract only Services.aspx from the link below
http : // localhost : 49169 / HirenSir / Services.aspx
using jQuery/javascript is admirable as then have to add a class to anchor tag containing this href parameter..
thanks
Upvotes: 1
Views: 65
Reputation: 46497
All the solutions so far work... how about a regex?
var url = "http://localhost:49169/HirenSir/Services.aspx";
// returns array of matches, should only contain one element
url.match("[^/]*$"); // ["Services.aspx"]
If you want it in a one-liner...
"http://localhost:49169/HirenSir/Services.aspx".match("[^/]*$")[0];
Upvotes: 0
Reputation: 55750
Try this in Javascript
var curPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
If your current location is Services.aspx
EDIT
If you want to add a class to the anchor in this case try this
$('a[href$="Services.aspx"]').addClass('selected');
Upvotes: 2
Reputation: 9576
"http://localhost:49169/HirenSir/Services.aspx".split('/').pop()
Upvotes: 1