Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: How to extract an anchor from href

Tags:

jquery

I am quite new to JQuery.

I would like to get the value of an anchor from a href with JQuery.

If I'd have the following example, how could i get the value "5" from the href with JQuery?

<a href="user/showUsers#5">User 5</a>

Thanks in advance

-James

like image 444
James White Avatar asked Dec 12 '12 08:12

James White


1 Answers

Use the following:

var id = $('a').attr('href').split('#');
id = id[id.length - 1];
like image 66
Tom Walters Avatar answered Sep 30 '22 18:09

Tom Walters