Solved

Counting number of list items in unorderd list and adding count

Posted on 2011-09-06
2
189 Views
Last Modified: 2012-08-13
Hi

I have an unordered list that is genereated dynamically. It looks similar to the attached code.

Within each list item there is a link and i want to add a number to the querystring in the link, so for example the first link would read post.html?s=2011-07-04-channelports-soft-launch&tid=1
(note the querystring tid=1)
so the second link would have 2 added to read tid=2, third link tid=3 and so on..

Any ideas how to do this with javascript?

thanks


<ul id="mycarousel" class="jcarousel-skin-portfolio">
  <li><a href="post.html?s=2011-06-29-riverside-brand-comms&tid="><img src="/newsite/perch/resources/1315292504riversidethumb.jpg" alt="Riverside Brand Comms" align="left" border="0" /></a><span>List 1</span></li>
  <li><a href="post.html?s=2010-07-20-annual-awards&tid="><img src="/newsite/perch/resources/1315292570awardsthumb.jpg" alt="Annual Awards" align="left" border="0" /></a><span>List 2</span></li>
  <li><a href="post.html?s=2011-07-04-channelports-soft-launch&tid="><img src="/newsite/perch/resources/1315292491cpthumb.jpg" alt="ChannelPorts Soft Launch" align="left" border="0" /></a><span>List 3</span></li>
</ul>

Open in new window

0
Comment
Question by:coolispaul
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36491346
You may use :
$("li a","#mycarousel").each(function(i,el) {
    //var href = $(this).attr("href") + i;  // start with tid=0
    var href = $(this).attr("href") + (i + 1); 
    $(this).attr("href", href); 
    // comment or delete this line (testing purpose)
    alert( $(this).attr("href") );
})

Open in new window


test page : http://jsfiddle.net/g6VBb/
0
 

Author Comment

by:coolispaul
ID: 36491372
perfect!

thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question