-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.

1

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.