Solved

Counting number of list items in unorderd list and adding count

Posted on 2011-09-06
2
187 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
Comment Utility
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
Comment Utility
perfect!

thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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 …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now