-2

I have generated unordered list which contains values (date representation) which I want to grab dynamically.

Html source looks like this

<ul>
    <li style="padding-left:7px;"> 
        <a href="/Repp/ByDay?day=20140808&amp;sport=0&amp;competition=0">fri 08.08.14</a>
        <a class="..." target="_blank"...></a>
    </li>   

I want to grab value 20140808 between

<a href="/Repp/ByDay?day= 

and

&amp;sport

UPDATE

I want to grab first value from this unordered list.

user1765862
  • 13,635
  • 28
  • 115
  • 220
  • see this: http://stackoverflow.com/questions/10126956/capture-value-out-of-query-string-with-regex – SoftSan Aug 08 '14 at 10:57

1 Answers1

2

This may be a good case for regular expressions. In jQuery-terms

$('a').each(function() {
  alert($(this).attr('href').replace(/^.*day=(.+?)&.*$/,'$1'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

<li style="padding-left:7px;"> 
  <a href="/Repp/ByDay?day=20140808&amp;sport=0&amp;competition=0">fri 08.08.14</a>
  <a class="..." target="_blank"...></a>
</li>

But if you can alter the HTML just add a data attribute containing your string:

$('a').each(function() {
  alert($(this).data('day'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<a data-day="20140808" href="/Repp/ByDay?day=20140808&amp;sport=0&amp;competition=0">…</a>
fboes
  • 2,149
  • 16
  • 17