0

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.

Bizboss
  • 7,792
  • 27
  • 109
  • 174
  • What have you tried? Are you able to get the href? Do you struggle with removing the "#slide" string? Conversion to a number? – Matt Zeunert Jan 24 '13 at 14:54
  • 1
    I googled the first line of your question and found the answer. http://stackoverflow.com/questions/872217/jquery-how-to-extract-value-from-href-tag – DickieBoy Jan 24 '13 at 14:55

3 Answers3

3

Something like this should work:

$('a').each(function() {
  alert($(this).prop('href').replace(/[^\d]+/, ''));
});
billyonecan
  • 20,090
  • 8
  • 42
  • 64
1
$('a').each(function(){
   alert($(this).prop("href").replace("#slide",""));
});
Anujith
  • 9,370
  • 6
  • 33
  • 48
0

Try this

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

LIVE DEMO

Codegiant
  • 2,110
  • 1
  • 22
  • 31