Solved

Counting number of list items in unorderd list and adding count

Posted on 2011-09-06
2
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

632 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