Dali
Dali

Reputation: 7882

jQuery: extract a part from a link Tag

How can I extract (with jQuery) the numbers from this a href Tags?

<a href="#slide1"></a>
<a href="#slide2"></a>
<a href="#slide3"></a>

Thanks a lot for help.

Upvotes: 0

Views: 77

Answers (3)

Codegiant
Codegiant

Reputation: 2150

Try this

$('a').each(function() {
  alert($(this).prop('href').replace(/[^\d]+/, ''));
});

LIVE DEMO

Upvotes: 0

Anujith
Anujith

Reputation: 9370

$('a').each(function(){
   alert($(this).prop("href").replace("#slide",""));
});

Upvotes: 1

billyonecan
billyonecan

Reputation: 20250

Something like this should work:

$('a').each(function() {
  alert($(this).prop('href').replace(/[^\d]+/, ''));
});

Upvotes: 3

Related Questions