Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Counting number of list items in unorderd list and adding count

Posted on 2011-09-06
2
Medium Priority
?
193 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 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

722 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